No module named flask using virtualenv

前端 未结 12 1262
生来不讨喜
生来不讨喜 2020-12-29 22:42

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

相关标签:
12条回答
  • 2020-12-29 23:25

    In Python 3.x

    pip3 install flask
    

    Worked fine for me.

    Thanks & Regards

    0 讨论(0)
  • 2020-12-29 23:28

    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

    0 讨论(0)
  • 2020-12-29 23:33

    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.

    0 讨论(0)
  • 2020-12-29 23:34

    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)
    
    0 讨论(0)
  • 2020-12-29 23:34

    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.

    0 讨论(0)
  • 2020-12-29 23:37

    Try below lines :

    $ python3.7 -m venv env 
    
    $ source env/bin/activate
    
    (env)$ pip install yourpackages
    
    (env)$ python app.py
    
    0 讨论(0)
提交回复
热议问题