5

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 contains flask folder.

If I put my app.py (simple Hello World app) inside "site-packages" folder, I don't get this error. But if put out of this three folder, but inside my flask_environment, I get this error.

Is something going wrong here?

The error:

Traceback (most recent call last):
  File "C:\Flask\flask_env\app.py", line 3, in <module>
    from flask import Flask
ImportError: No module named flask
leandrotk
  • 1,351
  • 4
  • 16
  • 27
  • 1
    So, with your environment activated, you get an error when you execute: `python -c 'import flask'` Also, can you show a stripped down version of your module that produces this error? – jaime Jun 12 '14 at 15:30
  • Are any of your files/folders called `flask`? If so this may confuse the import call. – Ffisegydd Jun 12 '14 at 15:35
  • 1
    Ffisegydd, I created a Flask folder to run virtualenv inside and to create flask_env folder – leandrotk Jun 12 '14 at 15:38
  • @user3159162 That tells you that flask is installed correctly. You should start the python interpreter and enter your script one line at a time, it should reproduce the error by the time you get to line 3 – jaime Jun 12 '14 at 17:55
  • @leandrotk make sure you activate your virtualenv before running the python file. – simanacci Jun 16 '16 at 15:21

5 Answers5

6

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

. venv/bin/activate
Dhananjay
  • 2,668
  • 1
  • 9
  • 11
3

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

 python3 'insert your file name here without the quotes'
ablshk
  • 31
  • 1
2

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

python no module name pika when importing pika

Community
  • 1
  • 1
Najeebullah Shah
  • 4,124
  • 3
  • 33
  • 46
2

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
FrozZerrer
  • 273
  • 1
  • 5
  • 15
0

run as python3 <file_name>

EX: python3 api.py

F.A. SULAIMAN
  • 389
  • 1
  • 3
  • 11