Skip to content Skip to sidebar Skip to footer

Python3 : Cannot Import Name Flask

I tried the following simple code, from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello World!' if __name__ == '__main__': app.run() it i

Solution 1:

A package is installed against a specific Python version/location. Installing Flask for Python 2 (which is probably what the python and pip commands are aliased to), doesn't install it for Python 3.

You should really just use virtualenv to control exactly what versions and packages you are using.

This creates a Python 3 environment and installs Flask:

virtualenv -p /usr/bin/python3 my_py3_env
source my_py3_env/bin/activate
pip install flask

When you open a new terminal, just source the activate script again to keep using the environment.


Post a Comment for "Python3 : Cannot Import Name Flask"