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
In Python 3.x
pip3 install flask
Worked fine for me.
Thanks & Regards
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
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.
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.py
from app import app
app.run(debug=True,host='0.0.0.0',port=5000)
On Windows even if you see (virtual_env_name) in the cmd line it is possible that the virtual environment is not completely activated. Deactivate/reactivate and try again.
Try below lines :
$ python3.7 -m venv env
$ source env/bin/activate
(env)$ pip install yourpackages
(env)$ python app.py