Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    need help for python in porting Krank to N900

    Reply
    pigling | # 1 | 2011-01-21, 06:04 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks

     
    dov | # 2 | 2011-01-21, 06:11 | Report

    Check your PYTHONPATH variable. It must include the directory in in which levels resides.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    pigling | # 3 | 2011-01-21, 06:19 | Report

    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?

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by pigling; 2011-01-21 at 06:28.

     
    dov | # 4 | 2011-01-21, 06:26 | Report

    The following should work:

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

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

    Edit | Forward | Quote | Quick Reply | Thanks

     
    pigling | # 5 | 2011-01-21, 06:53 | Report

    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?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    dov | # 6 | 2011-01-21, 11:27 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
vBulletin® Version 3.8.8
Normal Logout