12

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

gdogg371
  • 3,879
  • 14
  • 63
  • 107
  • *i am using Python 2.7 on Windows 10 I should add... – gdogg371 Jul 28 '18 at 12:28
  • 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. – SamrajM Jul 28 '18 at 12:38
  • yes have also tried the above installation method – gdogg371 Jul 28 '18 at 12:59
  • 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.py – SamrajM Jul 28 '18 at 13:05
  • have just tried that and no luck either – gdogg371 Jul 28 '18 at 13:17
  • Try directly installing the package to your directory from [here](https://github.com/google/google-api-python-client). 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. – SamrajM Jul 28 '18 at 13:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176939/discussion-between-samrajm-and-gdogg371). – SamrajM Jul 28 '18 at 13:27

3 Answers3

12

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
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
  • 1
    also, make sure if you running as `python3` not `python` (if you install both version) – Crazenezz Dec 27 '19 at 12:16
  • 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. – Mark Aug 29 '21 at 13:55
1

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

Manoj
  • 11
  • 1
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".

Shravya Mutyapu
  • 278
  • 2
  • 9