This is resolved in another thread: ImportError: No module named apiclient.discovery
Also this one worked in our case
pip install --upgrade google-api-python-client
Using python 3.6.5
Answer from Ananya_Chandraker on Stack OverflowI am making a simple YouTube API call where I am getting the statistics of a YouTube channel to learn how to make API Calls.
I am using the Google Python API and have pip installed it into my working directory. I got the ModuleError and then by troubleshooting online I thought of making a virtual environment and installing the google api in there.
After creating the virtual environment and installing the Google API in there I ran the command pip list to make sure that it is in the virtual environment and I get the output:
(playlist_venv) C:\Users\User\OneDrive\Desktop\Playlist_Creator>pip list Package Version ------------------------ -------- cachetools 5.5.0 certifi 2024.7.4 charset-normalizer 3.3.2 google-api-core 2.19.2 google-api-python-client 2.142.0 google-auth 2.34.0 google-auth-httplib2 0.2.0 googleapis-common-protos 1.65.0 httplib2 0.22.0 idna 3.8 pip 19.2.3 proto-plus 1.24.0 protobuf 5.27.4 pyasn1 0.6.0 pyasn1-modules 0.4.0 pyparsing 3.1.4 requests 2.32.3 rsa 4.9 setuptools 41.2.0 uritemplate 4.1.1 urllib3 2.2.2 WARNING: You are using pip version 19.2.3, however version 24.2 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
My script is as so:
from googleapiclient.discovery import build
import os
api_key = os.environ.get("YT_API_KEY")
if not api_key:
raise ValueError("YT_API_KEY environment variable not set")
# print(api_key)
youtube = build('youtube',
'v3',
developerKey=api_key)
request = youtube.channels().list(
part='statistics',
forUsername='******'
)
request = request.execute()
print(request)And the output is:
(playlist_venv) C:\Users\User\OneDrive\Desktop\Playlist_Creator>python3 youtube_call.py
Traceback (most recent call last):
File "C:\Users\User\OneDrive\Desktop\Playlist_Creator\youtube_call.py", line 9, in <module>
from googleapiclient.discovery import build
ModuleNotFoundError: No module named 'googleapiclient'What am I doing wrong to get this output?
This is resolved in another thread: ImportError: No module named apiclient.discovery
Also this one worked in our case
pip install --upgrade google-api-python-client
Using python 3.6.5
If your a Windows User and have Python Installed, then use the following command:
python -m pip install --upgrade google-api-python-client
This is my code I'm running in a Python3 Jupyter notebook:
from __future__ import print_function import datetime from googleapiclient.discovery import build from httplib2 import Http from oauth2client import file, client, tools import pandas as pd
I get this error:
ModuleNotFoundError: No module named 'googleapiclient'
pip freeze:
This is what I get from the command pip freeze:
apiclient==1.0.4 astroid==2.3.3 attrs==18.1.0 beautifulsoup4==4.7.1 cachetools==4.1.1 certifi==2020.6.20 chardet==3.0.4 colorama==0.4.3 ConfigArgParse==0.14.0 coursera-dl==0.11.4 cycler==0.10.0 entrypoints==0.3 google-api-core==1.22.1 google-api-python-client==1.10.0 google-auth==1.20.1 google-auth-httplib2==0.0.4 google-auth-oauthlib==0.4.1 googleapis-common-protos==1.52.0 httplib2==0.18.1 idna==2.10 isort==4.3.21 keyring==19.0.1 kiwisolver==1.2.0 lazy-object-proxy==1.4.3 matplotlib==3.3.0 mccabe==0.6.1 numpy==1.19.1 oauth2client==4.1.3 oauthlib==3.1.0 pandas==1.1.0 Pillow==7.2.0 protobuf==3.13.0 pyasn1==0.4.8 pyasn1-modules==0.2.8 pylint==2.4.4 pyparsing==2.4.7 python-dateutil==2.8.1 pytz==2020.1 pywin32-ctypes==0.2.0 requests==2.24.0 requests-oauthlib==1.3.0 rsa==4.6 selenium==3.141.0 six==1.15.0 soupsieve==1.9 typed-ast==1.4.1 uritemplate==3.0.1 urllib3==1.25.10 wrapt==1.11.2
I already tried:
-
pip install --force-reinstall google-api-python-client
-
pip install --upgrade google-api-python-client
-
Restarting my computer
-
Restart the Jupyter notebook kernel
-
When I try to use the command: "pip install googleapiclient", then I get this error:
ERROR: Could not find a version that satisfies the requirement googleapiclient (from versions: none)
ERROR: No matching distribution found for googleapiclient
What can I do?
Python provides various ways to install tools and packages.
Here's my standard setup:
python3 -m venv venv
source venv/bin/activate
python3 -m pip install google-api-python-client
Then you can write Python files or use the REPL by running e.g. python3:
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Then you can import the API Client Library and you should be good:
>>> from googleapiclient.discovery import build
>>> API_KEY = "[YOUR-API-KEY]"
>>> build("youtube", "v3", developerKey=API_KEY)
<googleapiclient.discovery.Resource object at 0x7bafdbcfd040>
When you're done consider deactivate'ing and removing the venv folder.
pip install google-api-python-client
This worked for me.
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
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
This is my code I'm running in a Python3 Jupyter notebook:
from __future__ import print_function import datetime from googleapiclient.discovery import build from httplib2 import Http from oauth2client import file, client, tools import pandas as pd
I get this error:
ModuleNotFoundError: No module named 'googleapiclient'
pip freeze:
This is what I get from the command pip freeze:
apiclient==1.0.4 astroid==2.3.3 attrs==18.1.0 beautifulsoup4==4.7.1 cachetools==4.1.1 certifi==2020.6.20 chardet==3.0.4 colorama==0.4.3 ConfigArgParse==0.14.0 coursera-dl==0.11.4 cycler==0.10.0 entrypoints==0.3 google-api-core==1.22.1 google-api-python-client==1.10.0 google-auth==1.20.1 google-auth-httplib2==0.0.4 google-auth-oauthlib==0.4.1 googleapis-common-protos==1.52.0 httplib2==0.18.1 idna==2.10 isort==4.3.21 keyring==19.0.1 kiwisolver==1.2.0 lazy-object-proxy==1.4.3 matplotlib==3.3.0 mccabe==0.6.1 numpy==1.19.1 oauth2client==4.1.3 oauthlib==3.1.0 pandas==1.1.0 Pillow==7.2.0 protobuf==3.13.0 pyasn1==0.4.8 pyasn1-modules==0.2.8 pylint==2.4.4 pyparsing==2.4.7 python-dateutil==2.8.1 pytz==2020.1 pywin32-ctypes==0.2.0 requests==2.24.0 requests-oauthlib==1.3.0 rsa==4.6 selenium==3.141.0 six==1.15.0 soupsieve==1.9 typed-ast==1.4.1 uritemplate==3.0.1 urllib3==1.25.10 wrapt==1.11.2
I already tried:
-
pip install --force-reinstall google-api-python-client
-
pip install --upgrade google-api-python-client
-
Restarting my computer
-
Restart the Jupyter notebook kernel
-
When I try to use the command: "pip install googleapiclient", then I get this error:
ERROR: Could not find a version that satisfies the requirement googleapiclient (from versions: none)
ERROR: No matching distribution found for googleapiclient
What can I do?
You should be able to get these dependencies with this simple install:
pip install --upgrade google-api-python-client
This is described on the quick start page for python.
apiclient was the original name of the library.
At some point, it was switched over to be googleapiclient.
If your code is running on Google App Engine, both should work.
If you are running the application yourself, with the google-api-python-client installed, both should work as well.
Although, if we take a look at the source code of the apiclient package's __init__.py module, we can see that the apiclient module was simply kept around for backwards-compatibility.
Retain apiclient as an alias for googleapiclient.
So, you really should be using googleapiclient in your code, since the apiclient alias was just maintained as to not break legacy code.
# bad
from apiclient.discovery import build
# good
from googleapiclient.discovery import build
» pip install google-api-python-client
You can add google-api-python-client to the requirements.txt file.
The following works:
gclient-service-account-auth==0.3.*
google-api-python-client~=1.4
At the time I tried, googleapiclient has to be locked to ~=1.4 (although the current version is > 2) because it is not backwards compatible for the dependent gclient-service-account-auth library.