No Module Named Flask Using Virtualenv
Solution 1:
This error can also appear if you start your Flask python server using ./run.py
or similarly use file associations to start your server. Then the python command in the association will be used instead of your virtual environment python command. Use python run.py
instead. See how my run.py innocently assumes /usr/bin/python?
#!/usr/bin/python# run.pyfrom app import app
app.run(debug=True,host='0.0.0.0',port=5000)
Solution 2:
I had this same problem on three Raspberry Pi units at the same time; beat my head against the wall trying to fix it for several hours (reinstall flask via pip, apt and aptitude - no joy).
Instead of:
pip install flask
I finally tried:
pip install Flask
Worked like a charm.
Solution 3:
Make sure you run your script after you've activated your virtualenv. On OS X you'd see (virtual_env_name)
at the start of each terminal line. To do this:
cd
to your virtualenv's directory and type . bin/activate
cd
to the directory containing the .py
file you want to run at app launch in the browser
Now enter python file_name.py
, for me the file name was routes.py
following this example
Solution 4:
This problem can also arise if the port is not available. Try running on different port.
Solution 5:
Activate your virtual environment first with
source bin/activate envName
Then try to run your command again
Post a Comment for "No Module Named Flask Using Virtualenv"