No module named googleapiclient.discovery
Asked Answered
R

3

14

I have been looking to implement the example Python scripts I have found online to allow me to interact with the YouTube API as per the GitHub link found here

The problem I am having is with the import statement at the start:

import argparse

from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

The online documentation requires the following command to install the googleapiclient library:

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

However, once installed I am still receiving an error that googleapiclient.discovery cannot be found. I have tried reinstalling via pip, with the following command line output generated, suggesting all is well:

Requirement already up-to-date: google-api-python-client in g:\python27\lib\site-packages (1.7.4)
Requirement not upgraded as not directly required: httplib2<1dev,>=0.9.2 in g:\python27\lib\site-packages (from google-api-python-client) (0.9.2)
Requirement not upgraded as not directly required: google-auth>=1.4.1 in g:\python27\lib\site-packages (from google-api-python-client) (1.5.0)
Requirement not upgraded as not directly required: google-auth-httplib2>=0.0.3 in g:\python27\lib\site-packages (from google-api-python-client) (0.0.3)
Requirement not upgraded as not directly required: six<2dev,>=1.6.1 in g:\python27\lib\site-packages (from google-api-python-client) (1.10.0)
Requirement not upgraded as not directly required: uritemplate<4dev,>=3.0.0 in g:\python27\lib\site-packages (from google-api-python-client) (3.0.0)
Requirement not upgraded as not directly required: rsa>=3.1.4 in g:\python27\lib\site-packages (from google-auth>=1.4.1->google-api-python-client) (3.4.2)
Requirement not upgraded as not directly required: cachetools>=2.0.0 in g:\python27\lib\site-packages (from google-auth>=1.4.1->google-api-python-client) (2.1.0)
Requirement not upgraded as not directly required: pyasn1-modules>=0.2.1 in g:\python27\lib\site-packages (from google-auth>=1.4.1->google-api-python-client) (0.2.2)
Requirement not upgraded as not directly required: pyasn1>=0.1.3 in g:\python27\lib\site-packages (from rsa>=3.1.4->google-auth>=1.4.1->google-api-python-client) (0.1.9)
pyasn1-modules 0.2.2 has requirement pyasn1<0.5.0,>=0.4.1, but you'll have pyasn1 0.1.9 which is incompatible.

What am I doing wrong?

Thanks

Reticent answered 28/7, 2018 at 12:27 Comment(7)
*i am using Python 2.7 on Windows 10 I should add...Reticent
Have you tried using python -m pip install --upgrade google-api-python-client to make sure that it's getting installed into the default interpreter? Also, you may want to add the information from your comment to the post.Hands
yes have also tried the above installation methodReticent
The googleapiclient requires you to install uritemplate.py. Have you tried: pip install uritemplate.py? If so, try force reinstalling it with: pip install --force-reinstall uritemplate.pyHands
have just tried that and no luck eitherReticent
Try directly installing the package to your directory from here. Click on "Clone or Download" button and save it as a zip file. Move it to your project directory and extract it there. Then move all the files from the folder it creates into the root directory of your project folder.Hands
Let us continue this discussion in chat.Hands
S
14

In case you are running Python3 (python --version), perhaps you should run this instead:

 pip3 install google-api-python-client

Another quick way to counter this problem could be to install the package in the same folder as your code:

 pip install google-api-python-client -t ./

That's not ideal but it will definitely work.


Or if you prefer to move external libraries to a lib/ folder:

pip install google-api-python-client -t ./lib

in that last case you will also need this at the beginning of your Python code:

import os
import sys
file_path = os.path.dirname(__file__)
module_path = os.path.join(file_path, "lib")
sys.path.append(module_path)

from googleapiclient.discovery import build
Smallscale answered 24/10, 2019 at 22:2 Comment(2)
also, make sure if you running as python3 not python (if you install both version)Gluttonous
Pay attention to the output messages from pip install. Pip may warn you that it has installed the library to a directory not on your PATH.Consanguinity
L
3

I faced similar issue while I was trying to write code involving 'YouTube API' in VS Code. On the suggestion by many folks from online coding forums I ran

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

but it didn't help.

Taking following steps resolved the issue for me:

In VSCode go to 'Settings' (Ctrl + , on Windows), inside 'Search settings' enter venv and under the heading for 'Python: Venv Path' enter the path for your virtual environment as seen in the following screenshot:

settings for Python: Venv Path in VS Code

And, then click on the Python interpreter in VS Code as seen below: (the selected interpreter reflects at the bottom left corner of the VS Code editor)

Python interpreter path

Leucocyte answered 24/7, 2021 at 14:56 Comment(0)
L
0

This solution is only applicable to those using "Visual studio" for building flask apps.(others can try though)

The only thing you need to check is "from where am I importing all my libraries" follow the process below while creating new env.

Python environments >(Right click) > Add new env > check the "View in python environments window".

Lefebvre answered 29/4, 2021 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.