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
Related
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.
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.
When I try to run a bot, I get this error message in the terminal:
zass#zass-system-product-name:~/python-telegram-bot/examples$python
echobot.py
/usr/local/lib/python2.7/dist-packages/python_telegram_bot-8.0-
py2.7.egg/telegram/utils/request.py:38: UserWarning: python-telegram-
bot wasn't properly installed. Please refer to README.rst on how to
properly install.
Traceback (most recent call last):
File "echobot.py", line 8, in <module>
import telegram
File "build/bdist.linux-x86_64/egg/telegram/__init__.py", line 94, in
<module>
File "build/bdist.linux-x86_64/egg/telegram/bot.py", line 34, in
<module>
File "build/bdist.linux-x86_64/egg/telegram/utils/request.py", line
33, in <module>
ImportError: No module named ptb_urllib3.urllib3
I'm running Python 2.7 on ubuntu, git and telegram bot are installed. - How can I fix it?
First of all make sure you have urllib3 installed. Sometimes urllib3 installation breaks. If for some reason your install of urllib3 is failing to include the util submodule, you could simply download the archive from the pypi page and copy the util folder from there to your urllib3 install location.
You may also issue the command below to get an up-to-date version:
sudo pip install urllib3 --upgrade
Then, see where your module is by starting a python interpreter and check where the urllib3 module is being loaded from:
python -c "import urllib3; print urllib3.__file__"
If all the above didn't work for you, make sure you're importing it right! and make sure there is no conflict.
If you clone the python-telegram-bot repo you need to run the following command before installing the code:
git submodule update --init --recursive
Then install the code with python setup.py install
Maybe you have 2 version of python and default version is 3.x
Try to check version of python
python -V
if default version is 3 then run your code with python version 2.
python2 echobot.py
it can be python2 or python2.7
Also it can be cause of versions of libs
I try to upgrade pip within a virtualenv following the instructions here. The upgrade fails because the system python cannot import the name Message from the email module.
(newsfeed)myhost:newsfeed admin$ pip install --upgrade pip
Traceback (most recent call last):
File "/Users/admin/newsfeed/newsfeed/bin/pip", line 7, in <module>
from pip import main
File "/Library/Python/2.7/site-packages/pip/__init__.py", line 9, in <module>
from pip.log import logger
File "/Library/Python/2.7/site-packages/pip/log.py", line 8, in <module>
from pip import backwardcompat
File "/Library/Python/2.7/site-packages/pip/backwardcompat/__init__.py", line 69, in <module>
from email import Message as emailmessage
ImportError: cannot import name Message
This problem is not just with upgrading pip but with installing anything within the virtualenv. When new package installations are attempted the same error occurs.
In a python terminal outside the virtualenv Message cannot be imported, but inside the virtualenv it can.
Also, in a different virtualenv on the same machine, there is no error installing or upgrading packages.
Why can't this virtualenv upgrade or install packages?
The standard library's email package is being shadowed (hidden) by a package or module named email(.py) in your path.
Locate the package by calling
python -c 'import email;print(email.__file__)'
and rename it or remove it.
Your pip is not inside the venv so you will probably not be able to upgrade it like this.
This is caused by the fact that you created a venv that uses system-packages. Remove the venv and recreate it by adding --no-site-packages as a parameter.
Followed instructions on the github page. Of course, had to make minor changes since I was working with a windows 7 system. I got to the point post creating the virtual environment for portia to run. And I was trying to install the required packages using pip.
pip install -r requirements.txt
It failed with a log.
Now in the shell I try to run twistd, it gives error saying command not found. I even tried as follows:
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$ python ../../portia_env/Scripts/twistd.py -n slyd
Traceback (most recent call last):
File "../../portia_env/Scripts/twistd.py", line 13, in <module>
from twisted.scripts.twistd import run
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 53, in
<module>
_checkRequirements()
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 37, in
_checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zop
e.interface.
(portia_env)
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$
Is there an alternate procedure to follow in order to make this work on windows?
It looks like zope.interface didn't install when you ran:
pip install -r requirements.txt
Could you try running the following and see if it works?
pip install zope.interface