Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialElias Sersun Uhalde
12,131 PointsCan't import Flask
Any idea why does this throw an "importError: cannot import name: 'Flask'?
from flask import Flask
from flask import render_template
app = Flask(__name__)
app.run(debug = True)
3 Answers
hum4n01d
25,493 PointsOk I figured it out. You canโt call the file flask.py because then its trying to import the name Flask from itself. Try naming the file app.py or something other than flask and it will work. You have to be careful in naming your files so that they donโt conflict with other packages.
hum4n01d
25,493 PointsYou have to install flask :) Try running pip install flask in your terminal. If that doesnโt work, try sudo pip install flask
Elias Sersun Uhalde
12,131 PointsI'm using the workspaces, isn't flask installed already?
hum4n01d
25,493 PointsI would think so... did that work?
Elias Sersun Uhalde
12,131 PointsI get back this:
treehouse:~/workspace$ pip install flask
Requirement already satisfied (use --upgrade to upgrade): flask in /usr/local/pyenv/versions/3.5.0/lib/python3.5
/site-packages
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in /usr/local/pyenv/versions/3.5.0/lib/p
ython3.5/site-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in /usr/local/pyenv/versions/3.5.0/lib/pyt
hon3.5/site-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): itsdangerous>=0.21 in /usr/local/pyenv/versions/3.5.0/
lib/python3.5/site-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): markupsafe in /usr/local/pyenv/versions/3.5.0/lib/pyth
on3.5/site-packages (from Jinja2>=2.4->flask)
You are using pip version 7.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
pyenv: cannot rehash: /usr/local/pyenv/shims isn't writable
and when I try to run the file I get the same error:
treehouse:~/workspace$ python flask.py
Traceback (most recent call last):
File "flask.py", line 1, in <module>
from flask import Flask
File "/home/treehouse/workspace/flask.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name 'Flask'
hum4n01d
25,493 PointsSee the answer, you need to run
sudo pip install flask
Elias Sersun Uhalde
12,131 PointsNot working either...
treehouse:~/workspace$ sudo pip install flask
bash: sudo: command not found
hum4n01d
25,493 PointsThatโs strangeโฆ can you send me a snapshot of the workspace?
Elias Sersun Uhalde
12,131 PointsOookey, i'm an idiot. Thank you so much for your help!
Elias Sersun Uhalde
12,131 PointsAlso thanks for all the help you've given me this past days.
hum4n01d
25,493 PointsNo problem! Could you mark my answer as correct?
hum4n01d
25,493 Pointshum4n01d
25,493 PointsBy the way, you donโt have any routes, Iโm not sure if that was what youโd wanted