PDA

View Full Version : Python


shortkid1101
08-18-2007, 08:56 PM
How do you run .py files in maemo? Ive done a lot of google searching and i cant find anything helpful.

alexib
08-19-2007, 06:37 AM
Hello shortkid1101,

if you are familiar with xterm and happy to use it, you can just type there "python filename.py".
Also you can do "chmod u+x filename.py" to make your python file directly executable and put "#!/usr/bin/env python" as a first line, then you can run it as any executable just by typing its name.

If you like to run it from program menu, you have to create a desktop file for it. For this you need root access. The desktop file should be put for example here: /usr/share/applications/hildon/filename.desktop. The content should be like this:

[Dekstop Entry]
Version=0.0.1(enter the version)
Encoding=UTF-8
Name=MyName(enter the name)
Type=Application
Exec=path_to_filename.py(enter the path to your file, it should be made executable as described above)
Icon=icon_filename(enter the name of icon file)
X-Osso-Service=MyName(enter the name)
X-Osso-Type=application/x-executable

icon_filename should be a filename of PNG file with icon image without .png extention. This file should be put in /usr/share/pixmaps folder.

In principle you can prepare a .deb file to install a desktop file and all necessary stuff without root privileges via Applicaton Manager but this is another quite long story.

WBR

Alexib

shortkid1101
08-19-2007, 12:13 PM
thanks a lot but when i type in python test.py it says "can't open file 'test.py': [errno 2] No such file or directory exists. I have tried the chmod u+x way and it says it doesn't exist also.

alexib
08-19-2007, 03:35 PM
Try to specify full path to test.py. If test.py is in your current folder, prepend ./ to it name.

alexib

shortkid1101
08-19-2007, 05:30 PM
I have it in just the basic folder like when i click on the Nokia icon i see Audio clips, documents, test, ect.

This is a log from x term.
/ $ python
[Gcc 3.4.4 (release) (CodeSummary ARM 2005q3-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>>lybniz/lybniz.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>

does that mean that there is a problem with the script?

alexib
08-19-2007, 06:18 PM
No, you shouldn't try to run .py file from python interpreter. You should just type "python lybniz/lybniz.py" in the command prompt:
$ python lybniz/lybniz.py
and press Enter.

shortkid1101
08-19-2007, 06:51 PM
when i type
/ $ python lybniz/lybniz.py
it says

python: can't open file 'lybniz/lybniz.py': [Errno 2] No such file or directory

alexib
08-19-2007, 06:57 PM
Then it means you specify wrong path to lybniz.py. What shows the following command?:
ls -l lybniz/lybniz.py

jethro.itt
08-20-2007, 08:13 AM
I have it in just the basic folder like when i click on the Nokia icon i see Audio clips, documents, test, ect.

That's actually /home/user/MyDocs. To start a Python script in there, use:


~ $ python /home/user/MyDocs/test.py


When you start an X Terminal, its working directory is by default already set to /home/user (also called ~), and so this will work as well:


~ $ python MyDocs/test.py

jethro.itt
08-20-2007, 08:29 AM
Oh, and remember that you can use file name completion when typing file names. For example, typing "/home/user/MyDocs/test.py" can be shortened to:


/h<Tab><Tab>M<Tab>t<Tab>


I.e. type "/", "h", press Tab twice, type capital "M", press Tab, type "t" and press Tab. Tab is the button with two arrows pointing left and right on the upper left corner of the virtual keyboard (not present on the larger thumb keyboard). If there are more than one possible file name, pressing Tab will not complete the file name, but pressing Tab again lists the possible completions. Then it's just a matter of adding more letters and pressing Tab again.

shortkid1101
08-20-2007, 01:24 PM
thanks so much, i got it now, you were a big help,