ImportError: No module named flask

后端 未结 5 1762
小鲜肉
小鲜肉 2021-01-07 04:05

I installed virtualenv, activated it, and installed flask. So I have three folders: Include, Scripts and Lib. This last folder contains the site-packages folder, that contai

相关标签:
5条回答
  • 2021-01-07 04:18

    If you are using python3 you have to change a little bit your wsgi file.

    I changed my xx.wsgi from using execfile() to using exec(). Here is what it looks like when it finally worked.

    activate_this = '/opt/flask/project_name/py3venv/bin/activate_this.py'
    exec(open(activate_this).read(), dict(__file__=activate_this))
    
    import sys
    sys.path.insert(0, '/opt/flask/project_name')
    
    from project_app_name import app as application
    
    0 讨论(0)
  • 2021-01-07 04:20

    check this stack answer, only instead of pika you have to type flask:

    python no module name pika when importing pika

    0 讨论(0)
  • 2021-01-07 04:25

    Please make sure you have activated virtual environment before running python file.

    . venv/bin/activate
    
    0 讨论(0)
  • 2021-01-07 04:33

    run as python3 <file_name>

    EX: python3 api.py

    0 讨论(0)
  • 2021-01-07 04:39

    try this command in the terminal instead of selecting 'run code':

     python3 'insert your file name here without the quotes'
    
    0 讨论(0)
提交回复
热议问题