0

I have installed Google APIs Client Library for Python via easy_install.py --upgrade google-api-python-client. When I run a script that contains from oauth2client.tools import argparser, run_flow returns:

Traceback (most recent call last):
File "C:\Users\name\Desktop\file.py", line 9, in <module>
from oauth2client.tools import argparser, run_flow
ImportError: cannot import name argparser

I am using python 2.7.6 64x in win 8. The strange thing is that doing the same procedure in another pc in win 7 it working perfect. What is going wrong?

Thanks.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Thoth
  • 993
  • 12
  • 36

1 Answers1

2

The argparser object was added on 29 March 2013, after google-api-python-client version 1.1 was released.

It appears your easy_install.py --upgrade google-api-python-client call failed to upgrade your local installation, you are still trying to import from version 1.1. The output of import oauth2client.tools; print oauth2client.tools.__file__ shows this:

C:\Python27\lib\site-packages\google_api_python_client-1.1-py2.7.egg\oauth2clie‌​nt\tools.pyc

You can see the version number in the egg path.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • It is strange I am facing the same problem again. I upgrate via `easy_install.py --upgrade google-api-python-client` and returned `Searching for google-api-python-client Reading https://pypi.python.org/simple/google-api-python-client/ Reading http://code.google.com/p/google-api-python-client/ Best match: google-api-python-client 1.2 Processing google_api_python_client-1.2-py2.7.egg google-api-python-client 1.2 is already the active version in easy-install.pth` – Thoth May 29 '14 at 17:47
  • `Using c:\python27\lib\site-packages\google_api_python_client-1.2-py2.7.egg Processing dependencies for google-api-python-client Finished processing dependencies for google-api-python-client` – Thoth May 29 '14 at 17:48
  • However, when running `import oauth2client.tools; print oauth2client.tools.__file__` returns `C:\Python27\lib\site-packages\google_api_python_client-1.1-py2.7.egg\oauth2clie‌​nt\tools.pyc`. Can we uninstall `1.1` version? – Thoth May 29 '14 at 17:49
  • Yes; see the second answer on http://stackoverflow.com/questions/1231688/how-do-i-remove-packages-installed-with-pythons-easy-install – Martijn Pieters May 29 '14 at 18:07
  • I am not sure that I understand what is described on the second answer. I am trying to do that with `easy_install.py -m`. Because I am a Windows user can you tell me which folder/file to load? Is this approach correct? – Thoth May 29 '14 at 18:38
  • @Thoth: delete `google_api_python_client-1.1-py2.7.egg` from `C:\Python27\lib\site-packages\`. Edit the file `easy-install.pth` in than same folder and remove any references to the `google_api_python_client-1.1-py2.7.egg` egg; if there is no reference to `google_api_python_client-1.2-py2.7.egg` in that file, change the references from 1.1 to 1.2 – Martijn Pieters May 29 '14 at 18:53
  • I realised that in the `site-packages` there was only `oauth2client-1.1-py2.7`. I thhought that via `easy_install.py --upgrade google-api-python-client` the `oauth2client-1.2-py2.7` would installed. Whatever, I installed manulally `oauth2client-1.2-py2.7` from [here](https://code.google.com/p/google-api-python-client/downloads/list) and problem solved. Thanks for your time! – Thoth May 29 '14 at 19:41