0

I have the following project skeleton.

ex47 
    bin/
    docs/
    ex47/
        __init__.py
    tests/
        __init__.py
        game_tests.py
    game.py
    setup.py

Working on Aptana Studio. In game_tests.py I have

from nose.tools import *
from ex47.game import Room

but Aptana is yelling at me for not being able to find Room, which I defined in 'game.py' as a class. When I run nosetests on command line I got Error: Import Error( no module named game). What's seems to be wrong?

3
  • What python traceback do you get when you run it? Commented Oct 24, 2012 at 20:49
  • 2
    Do you have an __init__.py in the top level ex47 dir? Commented Oct 24, 2012 at 20:53
  • Not really exactly relevant but you might try PyCharm IDE. There is a free and open source version and in my opinion much easier to use than Aptana because it automaticly handles a lot of issues like this for you. So especially you are not the most seasoned python guru you can at least get started on some really complex projects. Commented Jan 30, 2015 at 21:05

1 Answer 1

5

I see two issues:

  • topmost ex47 is not a valid package (there is no __init__.py)
  • topmost ex47 is not on your PYTHONPATH

The first one is obvious. If you want game.py to be importable using ex47.game then ex47 has to be a valid package. So most probably you wanted to put it in the inner ex47 which is a valid package?

When it comes to the second issue, python will look for ex47 on your PYTHONPATH and in the current directory (the one you are in when issuing commands). Probably none of those is the case, hence ex47 can't be found.

Considering the above, if you had the following directory structure:

ex47 
    bin/
    docs/
    ex47/
        __init__.py
        game.py
    tests/
        __init__.py
        game_tests.py
    setup.py

and tried to run tests like this:

nosetests tests

while being in the topmost ex47 directory it should work (note that there is no __init__.py inside the topmost ex47).

Sign up to request clarification or add additional context in comments.

8 Comments

How do I set ex47 to my PYTHONPATH?
For the duration of current session export PYTHONPATH=/path/to/ex47:$PYTHONPATH. If you want it in Aptana, then you should look into project properties, there are settings which allow you to modify the PYTHONPATH.
All right. I added /ex47 to PYTHONPATH just like how the manual did and I added init.py to top ex47 file. But Aptana still cannot read Room. What else can I do?
You don't need __init__.py in the top-level ex47. But in order to fix the issue, please try running nosetests from the terminal/console/shell in the way described. If that works, you will be sure that if inner ex47 is on PYTHONPATH everything's fine. Given that, we can figure out why Aptana doesn't get it.
From /ex47, I ran that and got Ran 1 test in 0.003sec and Error: Import Error (no module named game).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.