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 OverflowThis 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
» pip install google-api-python-client
Videos
I 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 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.
I tried many ways to PIP3 installed GooglePythonApi, but I still can't get away from this error
ModuleNotFoundError: No module named 'googleapiclient'
I have Anaconda installed in my Windows 10, this is the screenshot of the error in my Visual Studio Code.
Can somebody help?
I'm getting the following error:
Import "googleapiclient.discovery" could not be resolved Pylance (reportMissingImports)
when I add the following line to my code:
from googleapiclient.discovery import build
The file structure is as follows:
YOUTUBEAPI\youtube_api\Lib\site-packages and YOUTUBEAPI\youtube_api\yt.py
I don't know how to draw directory tree in reddit, so mentioned like the above.
also, when I check the discovery.py file inside "googleapiclient" folder similar error is found for the following lines of code:
from six.moves import http_client from six.moves.urllib.parse import urljoin
i.e. Import "six.moves" could not be resolved Pylance (reportMissingModuleSource) and Import "six.moves.urllib.parse" could not be resolved Pylance (reportMissingModuleSource)
Could somebody help me please?
Here is a screenshot so you guys can see what I am doing exactly.
https://ibb.co/rGVqMrj
Your submission in r/learnpython may be automatically removed because you used imgbb.com. The reddit spam filter is very aggressive to this site. Please use a different image host.
Please remember to post code as text, not as an image.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
You need to install that module in order to use it. Remember for pycharm you don't use pip, you use the pycharm packages window.
https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#packages-tool-window