Gmail API - ModuleNotFoundError: No module named 'googleapiclient' - Python 3.7 - python

Using the Gmail API in Python 3.7 to retrieve emails and I'm testing the code in both Terminal and Pycharm, yet I cannot get past line 7:
#!/usr/bin/env python3
import pickle
import os.path
import email
import base64
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
I recieve the error message:
from googleapiclient.discovery import build
ModuleNotFoundError: No module named 'googleapiclient'
I understand there have been other similar questions regarding this same issue but none of the answers appear to help in this situation.
Please see below for things I have tried and information which may help illicit a solution.
1) It appears that the packages are present and accounted for in the expected folders.
user/⁨PycharmProjects⁩/projectname/venv⁩/⁨lib⁩/python3.7⁩/site-packages
__pycache__
apiclient
cachetools
cachetools-4.1.0.dist-info
dateutil
easy-install.pth
easy_install.py
google
google_api_python_client_py3-1.2-py3.7.egg-info
google_auth-1.14.2-py3.8-nspkg.pth
google_auth-1.14.2.dist-info
google_auth_httplib2-0.0.3.dist-info
google_auth_httplib2.py
httplib2
httplib2-0.17.3.dist-info
numpy
numpy-1.18.4.dist-info
oauth2client
pandas
pandas-1.0.3.dist-info
pip-10.0.1-py3.7.egg
pkg_resources
pyasn1
pyasn1-0.4.8.dist-info
pyasn1_modules
pyasn1_modules-0.2.8.dist-info
python_dateutil-2.8.1.dist-info
pytz
pytz-2020.1.dist-info
rsa
rsa-4.0.dist-info
setuptools
setuptools-46.1.3.dist-info
setuptools.pth
six-1.14.0.dist-info
six.py
uritemplate
2) The project interpreters also appear to be correct:
3) Have tried reinstalling the module via PyCharm > Preferences
4) I have tried various pip commands including the following;
pip install google-api-python-client
pip install googleapiclient
pip install --upgrade google-api-python-client
Just don't understand what the issue is or how to resolve so your guidance and suggestions would be greatly appreciated.

You dont have 'google-api-python-client'. You instead have 'google-api-python-client-py3'. The former has to be available in the list of libraries:
I have installed it with:
pip install google-api-python-client
Also check if you are running the code with the same interpreter in which you installed google-api-python-client.

Related

azure functions module errors using python

I'm new to azure so excuse my lack of knowledge about the platform. I'm currently trying to run and deploy an azure function using python. these modules are currently found in my requirements.txt file
azure-functions
graphqlclient
requests
gql
asyncio
aiohttp
I run the following command pip install -r requirements.txt to install them, but for some reason, some modules cannot be found. for example the json module. import json works fine with any other python program. but when i try and add it to the requirements.txt file and run this command pip install -r requirements.txt i get the following error
ERROR: Could not find a version that satisfies the requirement json (from versions: none)
ERROR: No matching distribution found for json
i tried adding a version, but that did not solve my issue. thats only half my problem, i decided to ignore this problem for now and try to work with the modules that are working properly in the .txt file. moving on to my __init__.py file which is a timer trigger i have the following imports
import datetime
import logging
from graphqlclient import GraphQLClient
import requests
import asyncio
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
import azure.functions as func
but when i try and run my function i get the following error
Exception: ModuleNotFoundError: No module named 'gql.transport.aiohttp'
Can someone please explain these module erros? all these modules work fine when i run them from any other python program, so the problem seems to be from azure.
Thanks
I run the following command pip install -r requirements.txt to install them, but for some reason, some modules cannot be found. for example the json module.
Json is a standard library in python there's no need to install it.
Just include it in your python script as the following:
import json
Exception: ModuleNotFoundError: No module named 'gql.transport.aiohttp'
According to my test results, the default version of gql installed using the pip install -r requirements.txt command is 2.0.0.
If you use from gql.transport.aiohttp import AIOHTTPTransport to import AIOHTTPTransport, you need to install 3.x.x.
So this error is caused by version incompatibility.
Solution:
Please install the 3.x.x version of gql, you can uninstall the installed gql first, and then reinstall the new version of gql:
pip uninstall gql
pip install gql==3.0.0a5
I did some tests and the function can run normally.

from google.cloud import datastore gives 'ImportError: cannot import name 'collections_abc''

I am installing google cloud datastore to build a conversational chatbot, using the command
!pip install google-cloud-datastore
This gives me following error:
google-cloud-bigquery 1.9.0 has requirement google-cloud-core<0.30dev,>=0.29.0, but you'll have google-cloud-core 1.4.3 which is incompatible.
goes on to installing google-cloud-core-1.4.3 google-cloud-datastore-1.15.3.
Execute further
from google.cloud import datastore
gives following error:
/usr/local/envs/py3env/lib/python3.5/site-packages/google/cloud/_http.py in ()
20 import warnings
21
---> 22 from six.moves import collections_abc
23 from six.moves.urllib.parse import urlencode
ImportError: cannot import name 'collections_abc'
Package google-cloud-bigquery=1.9.0 seems to be old, I have google-cloud-bigquery=1.28.0. You can try to update first your Cloud SDK components and then install google-cloud-datastore again. You can update the components with:
gcloud components update
It is possible that you will be required to execute equivalent apt-get update command.
The second error with collections_abc seems to be a compatibility issue, python2 is being deprecated, please use Python3 (pip3). If the issue with six persists, try installing different version for instance; pip3 install six==1.15.0 as recommended in this github thread.

ImportError: No module named oauth2client.client in Gcloud

I wanted to deploy my app engine to use machine learning engine in Gcloud with the following code:
https://github.com/novinfard/temp
I encountered a strange error as follows:
ImportError: No module named oauth2client.client
However this library have already installed in app engine, as the following upgrade command return that everything is updated:
sudo pip install --upgrade google-api-python-client
I applied the 'vendor' solutions as described here as well:
https://stackoverflow.com/a/44011777/3477974
But this does not work either.
How this problem can be solved?
As of version 1.7.0 of google-api-python-client the hard requirement for oauth2client has been dropped. I.e. it will not be included when installing the google-api-python-client.
You can fix this by manually installing oauth2client in your vendor folder.
$ pip install -t <vendor_folder> oauth2client
This release drops the hard requirement on oauth2client and installs
google-auth by default instead. oauth2client is still supported but will
need to be explicitly installed.
https://github.com/google/google-api-python-client/releases/tag/v1.7.0

ImportError: cannot import name 'opentype' on new installation

I've just created a Google Cloud compute engine, installed google-cloud package with both pip and pip3, and I'm experiencing the following error when launching a script with python3
from google.cloud import bigquery
File "/usr/local/lib/python3.5/dist-packages/google/cloud/bigquery/__init__.py", line 35,
in <module>
from google.cloud.bigquery.client import Client
File "/usr/local/lib/python3.5/dist-packages/google/cloud/bigquery/client.py", line 36, in
<module>
(more traceback lines..)
from pyasn1_modules.rfc2459 import Certificate
File "/usr/local/lib/python3.5/dist-packages/pyasn1_modules/rfc2459.py", line 20, in <modu
le>
from pyasn1.type import opentype
ImportError: cannot import name 'opentype'
On the compute engine the following packages are installed:
pyasn1==0.1.9
pyasn1-modules==0.2.1
google-cloud==0.30.0
google-cloud-bigquery==0.28.0
Which can be the problem here?
Posting my solution in case it helps someone else - this fixed it for me:
pip install --upgrade google-auth-oauthlib
More details discussed here: https://www.raspberrypi.org/forums/viewtopic.php?f=114&t=198933&p=1241439#p1241439
It looks like you have an issue with pyasn1, so you could try installing a newer version (the latest is 0.4.2), or even reinstalling it manually with:
sudo apt-get --reinstall install python-pyasn1 python-pyasn1-modules
And if you are inside a virtualenv, use instead:
pip install pyasn1 pyasn1-modules
FWIW - Had the same issue - none of the above worked. I eventually discovered that if I did it under sudo it did work.
stracing the original - I found that I had a ~/.local directory which had a pyasn1 directory where it was trying to get the files from, but the opentype.py one did not appear there. When I deleted that whole directory - it started working.
I assume it was some sort of cache that was partial, and out-of-date???

ImportError: cannot import name SignedJwtAssertionCredentials

I'm trying to access a google app through the Python Client using this code to gain authorization (private info obviously redacted):
import gflags
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import SignedJwtAssertionCredentials
from oauth2client.tools import run
f = open('privatekey.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
service_account_name='name#developer.gserviceaccount.com',
private_key=key,
scope = 'https://www.googleapis.com/auth/calendar')
http = httplib2.Http()
http = credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http)
Yet I receive this error:
ImportError: cannot import name SignedJwtAssertionCredentials
I have installed the Google v3 API Python Client as well as OAuth2; I don't seem to be having any other problems with those modules, though I haven't used them much. Anyone know what's going on?
I had this problem today and had to roll back from oauth2client version 2.0 to version 1.5.2 with:
pip install oauth2client==1.5.2
It seems like you havn't installed pyopenssl. Install via easy_install pyopenssl.
Libraries oauth2client.client
if HAS_OPENSSL:
# PyOpenSSL is not a prerequisite for oauth2client, so if it is missing then
# don't create the SignedJwtAssertionCredentials or the verify_id_token()
# method.
class SignedJwtAssertionCredentials(AssertionCredentials):
....
The source repository was recently updated, to make use of the new code:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
...
As alexander margraf said you need PyOpenSSL to import SignedJwtAssertionCredentials
simply: pip install pyopenssl
REMEMBER: It will fail on Windows if you don't have OpenSSL Win32 libs installed http://slproweb.com/products/Win32OpenSSL.html (you need full package, not the light version). Also keep in mind you need to add it to your path var before installing pyopenssl
I was trying to build a local dev environment and none of the solutions here were working. The extra piece in the puzzle for me was:
$ pip install pycrypto
possibly in addition to any or all of:
$ pip install pyopenssl
$ pip install httplib2
$ pip install oauth2client
$ pip install ssl
GAE has the pycrypto package available internally (check the libraries listed in your app.yaml) so something needing it might work on their machines but not yours - I think - sorry I'm not yet clear on what and why they're making life so miserable with the libraries yet.
Check your oauth2client version first.
If this version >= 2.0, using the ServiceAccountCredentials instead of SignedJwtAssertionCredentials.
Look at the three reference:
Issue:
https://github.com/google/oauth2client/issues/401
Upgrade to 2.0
https://github.com/google/oauth2client/releases/tag/v2.0.0
Docs
http://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html#module-oauth2client.service_account
You can try this for oauth2client version >= 2.0,
from oauth2client.service_account import ServiceAccountCredentials
ServiceAccountCredentials.from_p12_keyfile(
service_account_email='name#developer.gserviceaccount.com',
filename=KEY_PATH,
scopes='https://www.googleapis.com/auth/calendar')
Check your `oauth2client' module version, probably you are using greater then 1.5.2 version if that is so, you can fix this problem by downgrading the version and reinstalling the 1.5.2 or 'oauth2client.client.AccessTokenCredentials'. Documentation link https://oauth2client.readthedocs.io/en/latest/source/oauth2client.client.html

Categories

Resources