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 Object-Oriented Python (retired) Hack-n-Slash The Final Push

Harish Vadlamani
Harish Vadlamani
1,724 Points

How do I run this game locally on my computer without the use of Treehouse Workspaces?

I have written all my code in dedicated folder but I cannot seem to get them working. I cannot seem to link files such as character, monster and combat as I get an ImportError! What should I do to rectify this?

Nicolas Bassano
Nicolas Bassano
2,125 Points

Hi Harish!

Can you share the code and your local folder structure?

What is your OS?

3 Answers

So if you are running Mac OSX, you should be able to go to the directory of your project. type python3 $SCRIPT

Your file tree should look like this: (I'll use 'main' as your directory name)

main/
    game.py
    character.py
    combat.py
    monster.py

Inside that file tree you can type python and run your import statements.

If you are having an issue importing when you run your script, see disclaimer(below) and make sure you are located in your file tree. Also ensure that your'e ensuring you are being case sensitive. Monster != monster.

game.py

#just to ensure you understand
import monster, character, combat

#do stuff

If you are using the interpreter:

#inside your file tree
>>> import monster
>>>
>>> m = monster()
>>> m
#whatever __init__ does

Disclaimer

When you import a file import monster not import monster.py

there is a workshop in the library for setting up python locally that may help

Harish Vadlamani
Harish Vadlamani
1,724 Points

@Gerald Wells, I'm running this on OSX.

Nicolas Bassano, here's the Github Repository of my code: https://github.com/harish3110/Python.git

Chris Bellmaine, Could you share the link for the workshop. Thanks!

Nicolas Bassano
Nicolas Bassano
2,125 Points

In case we dont see Chris Bellmaine for a wile.

The workshop he is (probably) mentionig is at....

https://teamtreehouse.com/library/setting-up-a-local-python-environment-mac

Youre a little bit ahead of me in the python track so I havent seen yet what youre trying to do.

Hope it helps anyway.

cheers.