No module named flask using virtualenv

Viewed 77880

I am following these steps to learn flask http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world/page/0#comments

I ran this command to create the virtual env:

python virtualenv.py flask

When I try to start flask using the python.exe file in my project scripts directory, it says

No module named flask

My PATH is set to the python directory that virtualenv installed. Why is it not able to find flask?

I initially started with the official Flask quickstart guide and was able to get the webserver to run, but with this virtual env install it is not working.

12 Answers

Make sure your virtualenv is activated. Then You check on the PYTHONPATH of that virtualenv. Is there a flask package (folder) installed in that directory.

If you unsure whether you have installed flask, just run the following command to see all the packages you have installed pip list or pip show flask. Do you see flask there? If not you can run pip install flask

Activate your virtual environment first with

source bin/activate envName

Then try to run your command again

If nothing else helps, check that in your code it is:

from flask import Flask

I've tried many things before I've noticed my mistake. I had this in my code:

from Flask import Flask

When I have changed capitalized letter for the module name, i.e. flask then everything worked.

In Python 3.x

pip3 install flask

Worked fine for me.

Thanks & Regards

For those of you on Windows who are running into this problem, have activated your venv and flask is installed in the right directory. For me I realized it was looking for flask but the file was called flask.exe. I renamed it and it worked perfectly.

Try below lines :

$ python3.7 -m venv env 

$ source env/bin/activate

(env)$ pip install yourpackages

(env)$ python app.py
Related