How to fix Python import google API error - python

from googleapiclient.discovery import build
After pip installing google api for python google tells me to use this command however the command doesn't work!
Can anyone help?
https://developers.google.com/docs/api/quickstart/python
Traceback (most recent call last):
File "C:\Users\M1\PycharmProjects\YouTube\main.py", line 1, in <module>
from googleapiclient.discovery import build
ModuleNotFoundError: No module named 'googleapiclient'
https://developers.google.com/docs/api/quickstart/python

I have installed the libraries using the following command:
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
Then, you can check that the library has been installed properly by running:
pip show google-api-python-client
Now, you should be able to import the libraries in your python code. Make sure that the code is executed within your virtual environment in case you are using one.

Related

ModuleNotFoundError: No module named 'passlib' despite passlib already being installed

I have a python module that tries to import from passlib.hash import pbkdf2_sha256, however when running the module, I get the ModuleNotFoundError.
I have tried running the module in my base environment, a venv, in a poetry shell, and I've tried reinstalling passlib through poetry install, pip install, pip install --force-reinstall, and none of it gets the module to see passlib being installed. I'm at a complete loss as to why this library just won't work.
The full error message is:
poetry run src/api-keychain/main.py --help
Traceback (most recent call last):
File "XXX/src/api-keychain/main.py", line 5, in <module>
from crypto import encrypt_key, decrypt_key
File "XXX/src/api-keychain/crypto.py", line 5, in <module>
from passlib.hash import pbkdf2_sha256
ModuleNotFoundError: No module named 'passlib'
Since you mentioned about you successful installed passlib, I guess you might not install it with the python interpreter you are using.
First Try:
pip install passlib
If not work, it could because you have both Python2 and 3 try:
pip3 install passlib
python3 -m pip install passlib
And if you have an IDE like Pycharm, you can use it to check what packages are with the interpreter you are using via go to the Interpreter Settings.

Error importing Biguery to anaconda jupyter notebook

i am trying to import a python package but I keep on getting an error;
from google.cloud import bigquery
the error being depicted after running is as seen below;
`ImportError Traceback (most recent call last)
in
1 #importing the python package
----> 2 from google.cloud import bigquery
ImportError: cannot import name 'bigquery' from 'google.cloud' (unknown location)
`
what could be the reason behind it? Please help.
As stated in the documentation, please do
pip install --upgrade google-cloud-bigquery
Make sure you use same python env in which you run your notebook. Or else you can run
! pip install --upgrade google-cloud-bigquery
in your notebook before importing.

ModuleNotFoundError while using tqdm after installation in python

I'm using a python code using the package tqdm, I installed it with pip
androiddl#androiddl:~$ pip install tqdm Collecting tqdm Using cached
https://files.pythonhosted.org/packages/76/4c/103a4d3415dafc1ddfe6a6624333971756e2d3dd8c6dc0f520152855f040/tqdm-4.30.0-py2.py3-none-any.whl
Installing collected packages: tqdm Successfully installed tqdm-4.30.0
After this success message when I'm trying to run my python script I have this error :
androiddl#androiddl:~/...$
python3 download.py "com.facebook.katana" Traceback (most recent call
last): File "download.py", line 10, in
from playstore.playstore import Playstore File "/home/.../playstore/playstore.py",
line 12, in
from tqdm import tqdm ModuleNotFoundError: No module named 'tqdm'
How can I fix it ? Thank you
It seems like pip is hooked up to Python 2, and not python3, which is what you are using to run your script. Try using pip3 instead. If that doesn't work, a quick way to solve it is to use python3 -m pip install ... for now, although it's nice to have that command located at pip3. Try looking at an answer like How to install pip with Python 3? for that.

Python SAML authentication

I'm trying to build a SAML authentication mechanism in Python using the OneLogin module, but I can't even get started. Trying from the example code provided in the docs, I can't even load the package.
This works:
import onelogin
but this gets a ModuleNotFoundError:
>>> from onelogin.saml2.auth import OneLogin_Saml2_Auth
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'onelogin.saml2'
I only managed to get this working on a Linux machine, so hope you're not on windows. Here's what worked for me.
I had to do a seperate install of hte xmlsec-library first:
apt-get install xmlsec1 openssl python-lxml libxmlsec1 libxmlsec1-dev
and then I was able to
pip install python3-saml
and there were no complains anymore.
You need to install Xmlsec first and then python3-saml but if you are on Windows, Xmlsec has some issues but as with python 3.6 and below the problem is solved. Use this link to download the wheel file for your python version https://github.com/mehcode/python-xmlsec/releases
Install the wheel file using
pip install <wheel_file_name>
As with Python 3.7, the only way out is to install xmlsec on a Linux machine as it is not yet supported on Windows.

Cannot install python six module

I have a server in the AWS cloud. It was running a flask API which calls the Google STT API fine. I then attempted to 'productionise' the API by setting up a virtualenv and getting the API to run there, with the intent of running Gunicorn.
When I tried to run the API in the virtual container it gave an error about importing the google api client. There was no google api client folder in my virtualenv so I copied folders across from the main python2.7 site-packages folder. Then I got an error saying it could not import six in googleapiclient/discovery.py. The error was "ImportError: No module named six".
There was no six directory in my virtualenv python folder. So I tried to copy across a folder named six-1.10.0.dist-info from my main python2.7 folder but that didnt help. I tried many things...such as forcing a reinstall but still the same error with the google api reference from googleapiclient/discovery.py. So I tried "sudo pip uninstall six; sudo pip install six". This successfully uninstalled, but now I cannot install again. When I run "sudo pip install six" I get the following:
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 48, in <module>
import six
ImportError: No module named six
I have also tried easy_install and options like --upgrade --ignore-installed but with no change in the behaviour.
What the heck is going on? Why cant I reinstall six? Why would it not be recognised anyway?
UPDATE
So this post stackoverflow.com/questions/13270877/… helped me to install six back into the main python environment. My API runs fine there now. But the same approach has not worked for the virtual environment.
Running "unset PYTHONPATH" seems to have helped me install modules into the virtualenv. The AWS image seems to have come with a python path already added that was confusing virtualenv. However I am still getting the nonsense below with six. What is going on?
(myprojectenv)[ec2-user#ip-172-31-29-83 myapi]$ python api.py
Traceback (most recent call last):
File "api.py", line 3, in <module>
from googleapiclient import discovery
File "/home/ec2-user/myapi/myprojectenv/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 20, in <module>
import six
ImportError: No module named six
(myprojectenv)[ec2-user#ip-172-31-29-83 myapi]$ pip install --upgrade six
Requirement already up-to-date: six in ./myprojectenv/lib/python2.7/site-packages

Categories

Resources