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 trial

Python

Monster.py

When trying to follow video 1 in object oriented python, I keep getting a ImportError: No module named 'monster' in the terminal.

My code is: class Monster: hit_points=1 color='yellow' weapon='sword'

Why does it work in the video and not in my terminal?

If you're using Workspaces, can you please share a Snapshot so we can see how your project is structured?

1 Answer

make sure you're typing it in the terminal exactly like so:

from monster import Monster

The capitalization is important.

Also, be sure you have the code saved in workspaces prior to trying to import. (Ctrl-S)

Also, be sure you named the file 'monster.py' and not 'Monster.py' :)

I have made sure I'm doing both and am still getting the same error. Any other suggestions?

No, because the error message you're getting is telling you explicitly that you don't have a module named monster.py :)

Open up a new workspace and try again -- perhaps there's a problem.

Make sure you name it monster.py and be absolutely sure to save the file after you're typed up your class.

If you didn't capitalize the class name, you would have gotten the error ImportError: cannot import name 'monster'

If you didn't type the file name in all lower case, or didn't type from monster for the first part of the import statement, or just didn't save the file, or use a .py extension, then you'd definitely get ImportError: No module named 'WhateverYouNamedTheFile'