0
votes

I started an empty Ubuntu (Ubuntu 14.04.3 LTS) workspace on cloud9. Python 2.7.6 was there by default. I installed python-pip and python-virtualenv (using apt-get).

Having created the smallest possible Flask application I've faced a problem: I get an import error if I press ide's Run button:

Cloud9FlaskProblem

Update

The same problem here: https://community.c9.io/t/not-able-to-run-python-file-which-has-a-import-statement-for-flask-installed-via-virtualenv-py/6151

If I run the application from terminal by issuing python app.py then everything's fine:

enter image description here

Virtual environment is activated.

pip list shows

...

Flask (0.12) - it's there.

...

which python shows

/home/ubuntu/workspace/env/bin/python

What's wrong with my setup?

1
Check your workspace settings. There is a setting somewhere about which Python version to use and you might have to flick that the other way. Once you do that, try running with the runner again and that may do the trick. - Brady Dowling

1 Answers

1
votes

If running from the terminal after activating the environment works fine maybe you could include the command to activate the virtual environment from within the script, for example:

import os
os.system("source env/bin/activate")
import flask

you may need to use an absolute path for the environment but that should be easy enough to find