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 Dice Roller Comparing and Combining Dice

Can't get to the correct directory for Die D6 classes

I keep getting an error message when I try to get to the yatzy directory in the python shell.

"/usr/local/pyenv/versions/3.5.0/bin/python: can't find 'main' module in 'yatzy/pycache/'"

Can anyone help with this?

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Could you provide a few more details so I can try to help? Here they are.

  1. Is this in Workspaces?
  2. What commands are you using to "try to get to the yatzy directory"?
  3. What command are you typing to run the script?

2 Answers

Yes, its in workspaces.

Im using this command "python yatzy/pycache/" after which I get the message "/usr/local/pyenv/versions/3.5.0/bin/python: can't find 'main' module in 'yatzy/pycache/' "

If I go into python shell directly, here are the commands and error messages I have gotten:

from yatzy/pychache/dice import D6
File "<stdin>", line 1
from yatzy/pychache/dice import D6
^
SyntaxError: invalid syntax
from dice import D6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'dice'

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hey Mohammad Aslam

So even though __pycache__ can be a folder that is generated when your script is run. This is usually not a folder you worry about trying to import your code from. The code inside there is byte code, no longer really Python.

There should be a file called dice.py in that folder. This means from your python shell you can treat the yatzy and dice as a module to import from.

So instead of from yatzy/pycache/dice try removing the pycache. Also use . as the separator.

It would look something like this from yatzy.dice import D6, then you have access to D6 inside your shell so you could create instances like dice_6 = D6()

Let me know if that helps with your problem!