zyyzxx
Posts: 16
Joined: Sat Aug 18, 2012 1:11 pm
Location: Cheltenham

program installation

Tue Apr 22, 2014 8:29 pm

I have written a pygame program which works fine under IDLE3. I want to call up the program directly without using the python environment. I have done this in the past as follows:
chmod +x mygame.py
sudo cp mygame.py /usr/local/bin
sudo mv /usr/local/bin/mygame.py /usr/local/bin/mygame

then mygame works from LXTerminal

This time my new program loads a number of image files which cant be found.
I get the response : No such file or directory
Where should the image files be located?

Regards Trevor

natlampen
Posts: 4
Joined: Sun Apr 13, 2014 12:13 pm

Re: program installation

Tue Apr 22, 2014 8:43 pm

I guess the images are placed in the original folder? If so, you should probably move to images too, or change the path to the images in your program

User avatar
rpdom
Posts: 17274
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: program installation

Wed Apr 23, 2014 5:54 am

You should probably include the full path name of the image files in your program to ensure it can find them wherever it is run from.

Also, the two commands

Code: Select all

sudo cp mygame.py /usr/local/bin
sudo mv /usr/local/bin/mygame.py /usr/local/bin/mygame
could just be written as one command (to save you a bit of typing :) )

Code: Select all

sudo cp mygame.py /usr/local/bin/mygame

zyyzxx
Posts: 16
Joined: Sat Aug 18, 2012 1:11 pm
Location: Cheltenham

Re: program installation

Wed Apr 23, 2014 1:34 pm

Thanks, have tried both options with the same result.
Regards Trev

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: program installation

Wed Apr 23, 2014 2:20 pm

Trev,

Can you provide any more detail e.g. the code and the full error message that you get?

el_P
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

zyyzxx
Posts: 16
Joined: Sat Aug 18, 2012 1:11 pm
Location: Cheltenham

Re: program installation

Thu Apr 24, 2014 9:54 am

Hi, the relevant fragment of code (from a minesweeper game) is:

# load the images
BOMBIMAGES = []
for i in range (0, NUMIMAGES+1):
bombImage = pygame.image.load('bomb%s.png' %i)
BOMBIMAGES.append(bombImage)
mineImage = pygame.image.load('mine.png')
mineRect = mineImage.get_rect()

After typing
minefinder
the response is
:No such file or directory

Hope this helps
Regards Trev

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: program installation

Thu Apr 24, 2014 11:22 am

OK, a few comments:
1) Please always post python code inside [ code ][ /code ] tags (without spaces). This preserves indentation which is vital for python
2) What is your game called? Your steps to move and rename the file seem to have called it "mygame" yet you seem to be typing "minefinder".
3) The script is looking for image files beginning "bomb". There's no filepath included in the script so I think the images would need to be in the same folder as the script.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
rpdom
Posts: 17274
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: program installation

Thu Apr 24, 2014 11:56 am

elParaguayo wrote:3) The script is looking for image files beginning "bomb". There's no filepath included in the script so I think the images would need to be in the same folder as the script.
I believe the script would look for the files in the current directory. i.e. the directory the user was in when they typed the command to run it. They really need the full path name of the image files to be included in the script.

Something like

Code: Select all

# load the images
BOMBIMAGES = []
for i in range (0, NUMIMAGES+1):
    bombImage = pygame.image.load('/home/pi/images/bomb%s.png' %i)
    BOMBIMAGES.append(bombImage)
    mineImage = pygame.image.load('/home/pi/images/mine.png')
    mineRect = mineImage.get_rect()

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: program installation

Thu Apr 24, 2014 12:03 pm

Thanks rpdom.

I'm still suspicious about #2 on my list, because the error doesn't look like a python error unless the rest of the error message is missing.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

zyyzxx
Posts: 16
Joined: Sat Aug 18, 2012 1:11 pm
Location: Cheltenham

Re: program installation

Thu Apr 24, 2014 7:15 pm

Hi,
I used "mygame" as an example for the post. The game is in fact called minefinder.
I have tried putting the full file spec in the Python script, with the same error message.

Regards Trev

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: program installation

Thu Apr 24, 2014 7:38 pm

Does your python script have the shebang as the first line? e.g.

Code: Select all

#!/usr/bin/python
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
rpdom
Posts: 17274
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: program installation

Thu Apr 24, 2014 7:59 pm

So your program is called minefinder and is now located in /usr/local/bin.

What does

Code: Select all

ls -l /usr/local/bin/minefinder
show?

Also what do you get if you type in

Code: Select all

echo $PATH
Last edited by rpdom on Fri Apr 25, 2014 3:48 pm, edited 1 time in total.

zyyzxx
Posts: 16
Joined: Sat Aug 18, 2012 1:11 pm
Location: Cheltenham

Re: program installation

Fri Apr 25, 2014 10:51 am

Hi,

I use a different shebang:
#!/usr/bin/env python

ls -l /usr/local/bin/minefinder
results in:
-rwxr-xr-x 1 root staff 12795 Apr 23 13:25 /usr/local/bin/minefinder

$PATH results in
bash: /usr/lib/arm-linux-gnueabihf/libfm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games: No such file or directory

Hope this helps
Trev

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: program installation

Fri Apr 25, 2014 2:23 pm

Can you run the file if you do:

Code: Select all

python /usr/local/bin/minefinder
The error you get does seem to be a bash error message rather than a python one. Have you got any stray characters before your shebang which may be confusing the interpreter?
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

zyyzxx
Posts: 16
Joined: Sat Aug 18, 2012 1:11 pm
Location: Cheltenham

Re: program installation

Sat Apr 26, 2014 12:52 pm

Hi,
Yes the program works fine if preceded by python ie:
python /user/local/bin/minefinder

The script includes the full file spec of the image files in my development directory.
I have confirmed there are no characters preceding the shebang.
Regards Trev

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: program installation

Sat Apr 26, 2014 12:58 pm

RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

zyyzxx
Posts: 16
Joined: Sat Aug 18, 2012 1:11 pm
Location: Cheltenham

Re: program installation

Sat Apr 26, 2014 8:32 pm

Hi,
Thanks for the reference to the problem with dos/unix file formats.
I carried out the suggested changes to the file formats using vim and the program now works correctly from any directory.
It was written originally under Windows, hence the dos file formatting.
Thanks for all the help, Trev

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: program installation

Sat Apr 26, 2014 10:07 pm

Great. Glad we could help.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Return to “Python”