简体   繁体   中英

No module named flask in virtualenv although installed

I want to use Flask to develop a website but I am having already problems getting a simple demo app running.

I followed the complete installation tutorial of the flask website
Means:

  • I created a project directory.
  • Inside this directory I created my virtualenv folder like described in the tutorial.
  • I started the virtual environment using . venv/bin/activate
  • I installed flask inside the virtualenv by pip install Flask

If I now open the python console via python (while running venv) and I try from flask import Flask I get the error:

Traceback (most recent call last): File "", line 1, in ImportError: No module named 'flask'

Also running a simple Hello World app like the following gives the same error. If I try to install flask again in venv, the following is shown in the console: 在此处输入图片说明

from flask import Flask
application = Flask(__name__)

@application.route("/")
def hello():
    return "hello world"

if __name__ == "__main__":
    application.run()

For completeness: I already searched a lot on SO and google but could not find the same problem. Although I found a few related all of them had the problem that the one asking either forgot installing flask inside venv or forgot activating venv etc.
Also if I type which python it points correctly to the folder bin/python inside my venv folder.

Okay, I solved the issue: If I use python3 instead of python to execute my program or to open python console everything works as expected.
Still, this is weird, because (inside venv) doing which python3 points to the python3 file inside the bin folder of my venv, but which python points to a symbolic link inside the same folder, which points again to exactly the same python3 file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM