Flask app can't find google module - python

I'm using a virtual environment to run a flask app. When I run pip freeze, I get the following:
google-api-core==0.1.1
google-auth==1.2.1
google-cloud-core==0.28.0
google-cloud-speech==0.30.0
google-gax==0.15.16
googleapis-common-protos==1.5.3
However, during run time, I get the following error:
from google.cloud import speech
ModuleNotFoundError: No module named 'google'
I'm using the google speech APIs. They work just fine when I run them locally. I don't understand why the app can't find the modules even though they're listed as installed. Can someone suggest a fix? I've tried doing pip install google, and it downloaded a bunch of other stuff, but still no fix.

So there are a lot of places where the error could be coming from. Could you please provide more details?
For example, which python version are you using? Python 2 or 3? If you are calling the wrong interpreter you need to type
python3 -m pip install
or
python3 -m pip install
accordingly.
Secondly are you using conda? If so, you need to use
conda install
instead of pip install. You can find out by typing which python in your terminal.
Third, are you sure you installed the google module correctly? If not try using
pip install google --user
and see if that works.
Lastly, are you installing the correct package? Because I believe for the speech api you need to do:
pip install --upgrade google-api-python-client

Well, removing the virtual environment and reinstalling all the dependencies worked.

It might be easier to add to your flask.py the path to modules you already installed:
import sys
sys.path.append("/home/ubuntu/.local/lib/python3.6/site-packages/")
import google
import gspread
That worked like magic to me at AWS.

Related

Install module in python locally

I have a very basic question. I want to install a new module on my computer in order to use it in Python (via Spyder). When I install the package via pip everything seems to work fine. When I want to import the package in my script it says that there is no module by that name (see scrennshot below)
Any suggestions what might be the problem?
Thanks a lot :)
screenshot of this problem
You're using pip3 to install.
Try installing using pip install nibabel.
Failing that, I would refer you to the following question:
Which pip is with which python?
This is a common pitfall of using different versions of Python and pip.
I think
/Applications/Spyder.app/Contents/MacOS/python -m pip install nibabel
or
/Applications/Spyder.app/Contents/MacOS/python -m pip3 install nibabel
will solve your problem
Thanks for asking the question.
Have tried conda install
Since we are in anaconda dev env.
If you are using windows
Windows: Click Start, search, or select Anaconda Prompt from the menu
and use that terminal
please find the reference
https://docs.anaconda.com/anaconda/install/verify-install/

Im having trouble importing a the request module in Python

I wanted to use the request library for python and I went to windows powershell and put in 'pip install requests'and it said install successful but when I open up an ide it says that it cannot find the import when I try to use it. How do I use a python import installed with the pip command?
suppose virtual environment issue
to check:
under powershell: pip show requests
notice the path it installed
under IDE, open the shell and type: pip show requests
it should show nothing if you inside the virtual environment. then simply pip install requests again, and then pip show requests, you would see the requests module under your venv folder

"ImportError: no module named 'requests'" after installing with pip

I am getting ImportError : no module named 'requests'.
But I have installed the requests package using the command pip install requests.
On running the command pip freeze in the command prompt, the result is
requests==2.7.0
So why is this sort of error happening while running the python file?
Run in command prompt.
pip list
Check what version you have installed on your system if you have an old version.
Try to uninstall the package...
pip uninstall requests
Try after to install it:
pip install requests
You can also test if pip does not do the job.
easy_install requests
I had this error before when I was executing a python3 script, after this:
sudo pip3 install requests
the problem solved, If you are using python3, give a shot.
One possible reason is that you have multiple python executables in your environment, for example 2.6.x, 2.7.x or virtaulenv. You might install the package into one of them and run your script with another.
Type python in the prompt, and press the tab key to see what versions of Python in your environment.
In Windows it worked for me only after trying the following:
1. Open cmd inside the folder where "requests" is unpacked. (CTRL+SHIFT+right mouse click, choose the appropriate popup menu item)
2. (Here is the path to your pip3.exe)\pip3.exe install requests
Done
if it works when you do :
python
>>> import requests
then it might be a mismatch between a previous version of python on your computer and the one you are trying to use
in that case : check the location of your working python:
which python
And get sure it is matching the first line in your python code
#!<path_from_which_python_command>
Opening CMD in the location of the already installed request folder and running "pip install requests" worked for me. I am using two different versions of Python.
I think this works because requests is now installed outside my virtual environment. Haven't checked but just thought I'd write this in, in case anyone else is going crazy searching on Google.

Cant import Eve module

Hello I recently installed Eve using pip3 install eve. But now I am having import problems. After installing eve from pip3. I can't import it. I tried it with Python3.3 and with Python2.7. When I try:
from eve import Eve
I get back Module not found error. Can you help me on this?
Are you using virtualenv? You probably should as it allows to you to isolate your Eve (or whatever) environment from others, and avoid conflicts in the process.
This said, installing Eve is as simple as hitting pip install eve(from inside the virtual environment if you're using virtualenv).
Try issuing a pip freeze, it will list the installed packages. Compare the list with Eve dependencies and make sure they have all been installed (you can use requirements.txt for comparison).
EDIT: you might also be facing privilege issues. Try installing with sudo pip install eve. But again, you should really be using virtualenv.
Good luck!

how to python-oauth2

I install python-oauth2 with pip install oauth2 and I find the dir named 'oauth2' in /usr/lib/python2.7/dist-packages
But from pyoauth2 import Client,AccessToken say: no moudles named pyoauth2
Then, I changed pyoauth2 to oauth2, same status.
I download the source code from https://github.com/douban/douban-client
I think you are installing the wrong package. Try with pip install pyoauth2.
oauth2 is a different package and does not define AccessToken.
It that works you can pip uninstall oauth2
Have you had problems with pip in the past?
Also have you tried to simply import oauth2 without specifying Client and AccessToken.
I pip installed oauth2 (windows) and AccessToken wasn't not found.
Also, are you running python in a separate terminal from the one which you called the pip install? You will have to restart python.
Worst case scenario, restart your machine.
Does any of this help?

Categories