Search code examples
pythonpython-3.xflaskvirtualenvflask-restful

Flask runs out of virtual environment


I was working in virtual environment but I removed the virtual environment folder in purpose. But I still can run flask restful application as below, while new empty virtual environment(there are no libraries in site packages but even application works like old virtual environment) is active.

flask run 

I thought it should have been failed and complaining like:

no module named flask

, because I removed the old proper virtual environment and installed new one then activated it.

And here is the point, when I try the run the main script as below

python3 app.py

It complains as expected:

no module named flask

It seems that when I run with flask run it is not using virtual environment even virtual environment is active. Because of this reason I can't test my application with other python versions and can't test if requirements are installed and run in new other virtual environments. I couldn't understand this behavior of the flask for any help I appreciate.

Thanks in advance.


Solution

  • Well I figured out what is going on there.

    Flask creates a directory named local in home and moved system's interpreter and dependencies there included by flask application that I wrote.

    Then it deploys the application from there when run with flask run. So that means my flask app was not running with virtual environment as we guess.

    So in that case I recreated my virtual environment and after installing dependencies I run with python3 app.py. Now it seems that it uses the virtual environment dependencies and interpreter.