maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   need help for python in porting Krank to N900 (https://talk.maemo.org/showthread.php?t=68704)

pigling 2011-01-21 06:04

need help for python in porting Krank to N900
 
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

dov 2011-01-21 06:11

Re: need help for python in porting Krank to N900
 
Check your PYTHONPATH variable. It must include the directory in in which levels resides.

pigling 2011-01-21 06:19

Re: need help for python in porting Krank to N900
 
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?

dov 2011-01-21 06:26

Re: need help for python in porting Krank to N900
 
The following should work:

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

I.e. you should add krank-07 to your PYTHONPATH.

pigling 2011-01-21 06:53

Re: need help for python in porting Krank to N900
 
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?

dov 2011-01-21 11:27

Re: need help for python in porting Krank to N900
 
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.


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

vBulletin® Version 3.8.8