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 trialRamkumar R
4,688 PointsImportError throws for models
When tried to run app.py got error
======
File "students.py", line 4, in <module>
import models
ImportError: No module named models
======
1) I have parent_folder inside app.py & models.py present
2) create a subfolder inside parent_folder put students.py
& __init__.py
files inside my subfolder
3) when run app.py throws above error
Using ubuntu 15.10 python version - 2.7.10
also tried import statement as from parent_folder import models
[MOD: added ```python and other formatting -cf]
1 Answer
Alexander Davison
65,469 PointsTry using Python 3. Python 2 is pretty different from Python 3, and Kenneth is using Python 3.
I highly recommend following along Kenny in Python 3, not Python 2.
Alex Koumparos
Python Development Techdegree Student 36,887 PointsAlexander is completely correct, but some people might be confused because in Workspaces, the python
command points to Python 3. But in most Unix and Unix-like environments python
points to Python 2.
Moreover, per PEP 394, this situation is likely to persist indefinitely (or at the very least until 2020), as the Python team recommends that distributions not move to pointing python
to Python 3 (since this could break legacy scripts) and instead to only use the command python3
to execute Python 3.
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsDo you have an
__init__.py
in the app.py directory as well? Can you post a link to your files or a shared workspace?