0

Trying to import flask but I get the error:

ImportError: No module named Flask

after:

import Flask

I just installed it using terminal (Mac OS X):

JoeDangers-MacBookPro:~ joedanger$ $sudo easy_install Flask
Searching for Flask
Best match: Flask 0.10.1
Processing Flask-0.10.1-py2.7.egg
Flask 0.10.1 is already the active version in easy-install.pth

Any thoughts as to why this is not working?

4 Answers 4

3

The module is called flask:

from flask import Flask
Sign up to request clarification or add additional context in comments.

1 Comment

Then your PYTHONPATH is invalid or the package didn't install correctly. Make sure easy_install uses the same PYTHONPATH as your Python interpreter.
1

You can use virtual environment

$ pip install virtualenv

Create virtualenv:

$ virtualenv venv

  • *venv is virtual environment name. Just name it what u want.

Activate virtual environment:

$ source venv/bin/activate

Make sure your terminal like this:

(venv) user@username:

Installing flask

pip install flask

And you can import flask without error :)

To deactivate, just type:

deactivate

Comments

0

uninstall the package and then reinstall it again using pip " pip install Flask " after that use this command to import the package:

from flask import Flask

edit:
are you using virtualenv ? if not then i recommend you to install it first use this command:

pip install python-virtualenv 

Comments

0

If your using mac terminal then check the python version which is linked to pip. Suppose for example if pip is linked to python version 2.7 use

➜  ~ python
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask

(or) 

➜  ~ python app.py

else if python version is 3.0 and above

➜  ~ python3
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask

(or)

➜  ~ python3 app.py

By using these commands you can check is flask is installed and if so for which python version

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.