0

I'm following a Flask tutorial and am getting an import error. I have a file called run.py which contains:

from app import app
app.run(debug = True)

When I run ./run.py, I get:

Traceback (most recent call last):
  File "./run.py", line 2, in <module>
    from app import app
  File "/Users/myName/Desktop/SquashScraper/app/__init__.py", line 1, in <module>
    from flask import Flask
ImportError: cannot import name Flask

This seems similar to this issue: http://stackoverflow.com/questions/26960235/python3-cannot-import-name-flask

So I attempted the checked solution by running:

virtualenv -p /usr/bin/python3 my_py3_env

Unfortunately, I get:

The executable /usr/bin/python3 (from --python=/usr/bin/python3) does not exist

Any ideas what may be happening here?

Thanks for the help, bclayman

anon_swe
  • 8,791
  • 24
  • 85
  • 145

1 Answers1

2

If you want your virtual environment to be Python 3 but don't know the installation directory, use which python3. Use that directory in your virtualenv -p [directory] my_py3_env command to set up the Python 3 virtual environment.

I sounds like your pip is installing to your Python 2.X directory. If you're okay with that, you'll need to run the app either with python2 run.py, python2.X run.py where x is your installed version, or change the symlink of python in /usr/bin/python to your installation of Python 2.

This question has some more information.

Regardless of the version of Python that you wish to use, you will need to install Flask to that version of Python. See this question for that.

Community
  • 1
  • 1
Celeo
  • 5,583
  • 8
  • 39
  • 41
  • Thanks for the help. I do what you suggest and now when I run ./run.py, I get "Import Error: cannot import name Flask"...thanks again! – anon_swe Jun 05 '15 at 21:28