0

Im trying to run python routes.py (inside a virtual environment) to get my routes to be updated, but when i run that, i get:

  File "routes.py", line 1, in <module>
    from flask import Flask, render_template
ImportError: No module named 'flask'

If I then try to install flask like pip install flask i get that its INSTALLED already

my routes.py looks like:

from flask import Flask, render_template
from forms import EmailUsForm

app = Flask(__name__)

app.secret_key = '12345'

@app.route('/')
def home():
    form=EmailUsForm()
    return render_template('index.html', form=form)

If I type: python then import Flask or from Flask import * I get:

ImportError: No module named 'Flask'

Any idea what is going on here?

Thank you.

Jshee
  • 2,620
  • 6
  • 44
  • 60

1 Answers1

0

U have to install Flask in your virtual environment, Since you are using Python3.x, use

pip3 install flask

Because if you use pip it will be installed for Python2.x by default

Manel
  • 176
  • 4
  • 16
  • If I do this with the env enabled, it says: sudo: pip3: command not found – Jshee Dec 11 '16 at 16:20
  • Then you should first install pip for python 3 by sudo apt-get install python3-pip – Manel Dec 11 '16 at 16:23
  • Or you can refer this post http://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3 – Manel Dec 11 '16 at 16:24
  • I then, installed `flask` via `pip3`, but if i try to run `python routes.py` it says it cant find `flask` – Jshee Dec 11 '16 at 16:24
  • `Requirement already satisfied: flask in /usr/local/lib/python3.5/dist-packages`. If i then try to import it via `python` then `from flask import *` or `import flask` it says `ImportError: No module named 'flask'` – Jshee Dec 11 '16 at 16:28
  • Refer these posts it may help http://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3 – Manel Dec 11 '16 at 16:31
  • http://stackoverflow.com/questions/20414015/no-module-named-flask-using-virtualenv – Manel Dec 11 '16 at 16:31
  • http://stackoverflow.com/questions/31252791/flask-importerror-no-module-named-flask – Manel Dec 11 '16 at 16:31
  • Try modifying your wsgi file http://stackoverflow.com/questions/24188240/importerror-no-module-named-flask – Manel Dec 11 '16 at 16:33
  • The `virtualenv` is enabled before i try to run `python routes.py` – Jshee Dec 11 '16 at 16:34
  • also `ls /usr/local/lib/python3.5/dist-packages` shows the `flask` directory in there – Jshee Dec 11 '16 at 16:35
  • If its python 3 then try python3 routes.py – Manel Dec 11 '16 at 17:12