I installed tzwhere on an AWS EC2 instance using Python 2.7 and:
pip install tzwhere
When I import it in Python at "/opt/python/run/venv/lib/python2.7/site-packages", where it is installed, it works, but I cannot import it anywhere else. I added "/opt/python/run/venv/lib/python2.7/site-packages" to my system path, but it did not help.
I'll appreciate it if you guide me how to solve this problem.
Let me explain more details: I am deploying a Django 1.6 project on Amazon Elastic Beanstalk. I need to import tzwhere only once when I deploy the project. So I imported it in setting.py. When I activate the virtual environment (explained in this post), I am able to import tzwhere in python, but when I run:
sudo python manage.py schemamigration southtut --initial
It returns the following error message:
ImportError: Could not import settings 'JoinWikipedians.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named tzwhere
When I deactivate the virtual environment, importing tzwhere returns the import error. In addition, in any python environment, when I use:
sys.path.append('/opt/python/run/venv/lib/python2.7/site-packages')
I can import tzwhere, but the same code before importing tzwhere in my setting.py does not help.
I found the solution. The problem was that AWS EC2 has some problem with pip install tzwhere. Whenever I tried to install it, it returned the memory error message. I completely removed it and installed pytzwhere, using:
git clone --recursive https://github.com/pegler/pytzwhere.git
python setup.py install
Now it works perfectly.
Related
Here is my file structure and requirements.txt:
Getting ModuleNotFoundError, any help will be appreciated.
main.py
from fastapi import FastAPI
from .import models
from .database import engine
from .routers import ratings
models.Base.metadata.create_all(bind=engine)
app = FastAPI()
app.include_router(ratings.router)
The error comes from the fact that you were not using the right environment and python version on VSCODE.
Your environment knew your different packages, but VSCode probably did not take them into account.
The solution was, in VSCODE: CTRL + SHIFT + P then Python:select interpreter and choose the version of python linked to your environment.
You can try to change the version of python to see the consequences on your imports
Try this to install all dependencies:
$ pip install "fastapi[all]"
Try this :
python -m pip install fastapi uvicorn[standard]
I am used to see import errors of my own modules.
But this time, this is about modules installed via pip and located in site-packages.
Here is a test file expurged from everything but just the imports :
import flask
import pygments
from flask_restful import Resource, Api
#from weather_tool import *
#from flask_restless import *
while running pytest :
Traceback:
test_MonAPPflaskRest.py:3: in <module>
from flask_restful import Resource, Api
E ModuleNotFoundError: No module named 'flask_restful'
Actually, every module with an underscore will fail !!!
flask_restless will fail to import to.
But it work when executed outside of pytest, or simply on the python shell...
Ok, I went through it.
Actually, Anaconda was installed. From here, no problem with that.
I installed Python from source as I'm used to do on a Linux platform and it works normally as expected.
I found out that pytest was not is the list of packages installed via pip.
Seems Anaconda provides a default pytest install. Maybe something is wrong with this version. (which pytest will return a pystest file in the python bin directory.
Actually, a simple pip install pytest in your virtualenv will 'overwrite' this - maybe messy - pytest version.
However calling pytest won't still work. You have to user py.test.
I know this is pretty much empirical. But that's it...
I got a similar error while importing stocker (Unable to find stocker module).
Try adding your 'code directory' to 'sys.path' where python looks for modules and it should be able to import then.
For more details:
https://bic-berkeley.github.io/psych-214-fall-2016/sys_path.html
I used the code:
>>> import sys
>>> sys.path.append('code') # code = the directory where your module is saved
>>> # Now the import will work
>>> import a_module # a_module = the module you are trying to import
I also faced the same issue when installed in virtual environment. I've deactivated virtual environment, installed flask-restful from PIP and then activated virtual environment. The issue is resolved.
I am creating a Python Web App in Google App engine.
When I
sudo pip install
a third party library and then try to import it, I get the error 'ImportError: No module named x'. Where x is the name of that library. In my case as an example: Boto, Boto3, Fask etc.
If I go into shell in GAE and type python >> import X the library can be used inside the python environment. When deploying the app though or running the app in the virtaul server in Google App Engine I get the module import error.
I even tried methods like: python >> import sys >> sys.path.insert(0, "path_here")
export PYTHONPATH and selected where those libraries are located
I even followed several Q&A here in Stackoverflow without any success, can somebody please give me a proper way to fix the import error in Google App Engine?
FYI
I am not using any local environment in my pc, I am working directly through the GAE bash console, the launch code editor in GAE and I am running the command dev_appserver.py $PWD
When I do
pip freeze
I can see that the modules are currently installed and deployed on the GAE virtual environment. Is there a problem with my path? What's the best approach to make GAE load my already installed third party libraries.
UPDATE:
Importing the library directly on the python shell from Google App Engine works just fine. Importing the library on my python app index.py file results in the error.
Python import directly from Shell
Python import to the index.py file
Though this is an old thread, adding this answer now:
Run command : gcloud components list
This will show the different components installed and not in your environment.
Install app-engine-python components if not installed:
gcloud components install app-engine-python
gcloud components install app-engine-python-extras
If it doesn't work:
In Windows, uninstall and download and install Google-sdk (check the python version you need). Delete all the files the installer ask you to delete in the last step and run the gcloud component commands again.
When I run a python script that I set up on WebJobs in Azure - I get the following error:
import MySQLdb
ImportError: No module named MySQLdb
job failed due to exit code 1
I found some articles that seem to suggest to install python modules to a directory created on the webapp. How/Where would I install those modules?
Have you tried this?
http://nicholasjackson.github.io/azure/python/python-packages-and-azure-webjobs/
(from the site):
Step 1.
If you are using OSX and the default Python 2.7 install your packages
installed with pip will be in /usr/local/lib/python2.7/site-packages,
create a folder called site-packages in the root of your python job
and copy any packages you need for your job into it.
Step 2
Next you need to modify your run.py or any other file which requires
access to the package files. At the top of the file add….
import sys
sys.path.append("site-packages")
In fact I cannot use any pakage now!
importerror: no module named flask.ext.script
importerror: no module named Pymongo
It seems that you virtual environment doesn't work. You've installed the flask-script package, but when you run the script, it still looks for it in C:\Python3.4. You may give us more info so that we can figure it out where is wrong. (How do you install it, how do you active the virtualenv, does reinstall virtualenv work, close the cmd shell and try again works?)
Also note that from flask.ext.extension import xxx is the old way to use the flask extension. Instead you should use from flask_script import Manager, Server if you are using the latest flask-script 2.0.5
If you are using the IDE such as pycharm, then maybe need to set the interpreter of python for the right version. Otherwise the packages that you have installed can not be used for the current project. I have also encountered such kind of questions until I set my IDE's interpreter to the Python 2.7.
Then you can freely import the flask_script
I think you should use python 2 to use this module flask.ext.script" because this is the old way of doing it, or you could install Flask-Script and import it this way from flask_script import ...
from flask.ext.extension import xxx is the old way of importing extensions ,now it's not working .You have to freeze first to outputs the package and its version installed in the current environment . Then you can check your module and import it as usual
e.g: -from flask_bcrypt import Bcrypt
#this import the Bcrypt from flask_bcrypt