9

New to python, and trying to install a module "apiclient" since my ide pycharm does not recognize that import:

from apiclient.discovery import build

what I tried:

  1. pip install apiclient
  2. download manually the package from

https://developers.google.com/api-client-library/python/start/installation#system-requirements then I extracted it into

/Users/nirregev/anaconda/bin/google-api-python-client-1.5.0

and ran this on my mac terminal python setup.py install but still pycharm does not recognize this module. According to pycharm I have the following interpreters installed:

/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
/Users/nirregev/anaconda/bin/python
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Eric
  • 2,636
  • 21
  • 25
Nir Regev
  • 135
  • 1
  • 2
  • 7

5 Answers5

20

Try this:

sudo pip install --upgrade google-api-python-client

OR

Make sure you only have google-api-python-client installed. If you have apiclient installed, it will cause a collision. So, run the following:

pip install --force-reinstall google-api-python-client

Answer Source

Community
  • 1
  • 1
Kaleem Ullah
  • 6,799
  • 3
  • 42
  • 47
  • does it matter from which location in the file system I will run pip ? – Nir Regev Mar 14 '16 at 08:49
  • 3
    I just ran these 2 pip commands and it says "requirement already met" – Nir Regev Mar 14 '16 at 08:51
  • yes it matter if you use virtual environments. better to run pip in project directory. and for more information please click Answer Source. this will help you more. – Kaleem Ullah Mar 14 '16 at 10:04
  • /Users/nirregev/anaconda/bin/python /Users/nirregev/PycharmProjects/test/PrepareTrainingData.py Traceback (most recent call last): File "/Users/nirregev/PycharmProjects/test/PrepareTrainingData.py", line 3, in from apiclient.discovery import build ImportError: No module named 'apiclient – Nir Regev Mar 14 '16 at 10:19
  • look over [here](https://github.com/google/google-api-python-client/issues/32) Due to an issue around in-place upgrades for Python packages, it's not possible to do an upgrade from version 1.2 to 1.3. Instead, setup.py attempts to detect this and prevents it. Simply remove the previous version and reinstall to fix this. – Kaleem Ullah Mar 14 '16 at 10:44
  • could you provide more details? remove what exactly and how ? thanks – Nir Regev Mar 14 '16 at 11:57
  • it says that the module version you are using is not compatible with your app. so look for the the version in `setup.py` and make it appropriate. i.e remove and install that one which match with you're app environment. try to make clean and new installation of all the dependencies. – Kaleem Ullah Mar 14 '16 at 18:12
  • The force-reinstall didn't work for me. I had to uninstall "apiclient" and "google-api-client-python-client" first and then install "google-api-python-client" again – TimSmith-Aardwolf Jun 14 '17 at 14:04
4

I ran into this problem and had a tough time figuring it out. In the end, this worked for me:

pip install google-api-python-client==1.5.3

Before doing this, I had version 1.6.2 installed. What I think is going on is that later versions of google-api-python-client dropped the apiclient in favor of the googleapiclient alias; which is an issue because some packages (e.g. airflow) still use that apiclient.discovery import.

Hope this helps.

1

If you have python3 installed somewhere and you are to install apiclient, it may be installing it in your python3 directory. I had the same problem and when I uninstalled python3 my program ran smoothly.

Steel
  • 11
  • 1
1

If you have got both python 2 and python 3 and you're trying to use python 2 for this purpose try the following: sudo pip2 install google-api-python-client==1.5.3 . This worked for me.

Aanchal Adhikari
  • 303
  • 4
  • 12
0

I am on Mac, using brew's python, and this worked for me:

1 - As suggested by others, install the API client using pip:

sudo pip install --upgrade google-api-python-client

2 - Make sure you are calling the library in your code as googleapiclient, and not as apiclient, which is deprecated.

3 - Tell Python to look for packages in the pip folder:

export PYTHONPATH=/usr/local/lib/python2.7/site-packages

To make it permanent, add the above line to either your .profile or .bash_profile file in your $HOME.

coccoinomane
  • 858
  • 8
  • 24