Active Topics

 


Reply
Thread Tools
Posts: 27 | Thanked: 8 times | Joined on Jan 2009 @ Singapore
#1
Hi all,
I am trying to port Krank python game to N900 but there are questions that I can't handle. Now I try to run the program on Ubuntu 8.04 and the errors
Code:
  File "/home/ubuntu/krank-07/src/Main.py", line 9, in <module>
    from World  import *
  File "/home/ubuntu/krank-07/src/World.py", line 8, in <module>
    from Level  import *
  File "/home/ubuntu/krank-07/src/Level.py", line 2, in <module>
    import k, levels
ImportError: No module named levels
In fact, there is already a __init__.py in "levels" folder. I want to google but can't find a proper solution as a python newbie. Can some python programmer help? Thanks.

regards,
pigling
 
Posts: 81 | Thanked: 45 times | Joined on Dec 2009
#2
Check your PYTHONPATH variable. It must include the directory in in which levels resides.
 
Posts: 27 | Thanked: 8 times | Joined on Jan 2009 @ Singapore
#3
thanks for your kindly reply.
following is the folder structure:
Code:
krank-07/
    krank
    src/
        Main.py
        Level.py
    levels/
        __init__.py
original krank code as follow
Code:
#!/bin/sh
KRANKPATH=`dirname $0`
PYTHONPATH=$KRANKPATH:$PYTHONPATH
export PYTHONPATH
python $KRANKPATH/src/Main.py
now I change it to
Code:
#!/bin/sh
KRANKPATH=$( (cd -P $(dirname $0) && pwd) )
PYTHONPATH=/home/ubuntu/krank-07:/home/ubuntu/krank-07/levels
export PYTHONPATH
echo $PYTHONPATH
sudo nohup python $KRANKPATH/src/Main.py &
"sudo nohup python $KRANKPATH/src/Main.py &" is added because I want to see the log and make script run background otherwise the program will hang and I have to force quit.

I set PYTHONPATH to /home/ubuntu/krank-07 where Main.py stays. so you suggest to add /home/ubuntu/krank-07/levels in PYTHONPATH?

Last edited by pigling; 2011-01-21 at 06:28.
 
Posts: 81 | Thanked: 45 times | Joined on Dec 2009
#4
The following should work:

cd src
export PYTHONPATH=`pwd`:..
python Main.py

I.e. you should add krank-07 to your PYTHONPATH.
 
Posts: 27 | Thanked: 8 times | Joined on Jan 2009 @ Singapore
#5
now I change it to
Code:
cd src
export = /home/ubuntu/krank-07:/home/ubuntu/krank-07/src:/home/krank-07/levels
python Main.py
above error solved. But new error happens
Code:
Traceback (most recent call last):
  File "Main.py", line 66, in <module>
    pygame.display.set_icon(pygame.image.load('levels/images/icon64x64.png'))
pygame.error: Couldn't open levels/images/icon64x64.png
I check that icon64x64.png exists. Is this a path issue or pygame library issue?
 
Posts: 81 | Thanked: 45 times | Joined on Dec 2009
#6
Just read the error messages. It doesn't find levels/images/... . So try moving to a path where it will find this file. Thus do

cd /home/ubuntu/krank-07
python src/Main.py

and the above path problem should go away.
 
Reply


 
Forum Jump


All times are GMT. The time now is 12:08.