maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Help with Python please (https://talk.maemo.org/showthread.php?t=23761)

Munk 2008-09-21 00:12

Help with Python please
 
I've done 20 minutes of searching and believe that it was a good effort.

My question:
I did some VERY EASY development on my Windows machine with Python 2.5 installed along with PyGame 1.7. I copied my program called "time.py" over to my NIT expecting it to work there since it really is a simple program and it was copied from another NIT Python app.

On my NIT, I have been running other peoples Python scripts from:
/home/user/py

The script originally came from one already working on my NIT. I didn't change any of the imports at the beginning and the script begins with:
#!/usr/bin/python

I first used:
chmod +x time.py

But when I try to run it with ./time.py it says:
/bin/sh: ./time.py: not found

What am I not understanding here? Is this more that a file needs to be in a specific place? Is it that a Windows file has different privileges and I need to set it on Linux? I tried compiling it by running:
python -OO time.py

but it too says it cannot find the file. I know that PluThon exists but I really think this should work without installing more stuff.

Help.

maacruz 2008-09-21 00:57

Re: Help with Python please
 
/bin/sh: ./time.py: not found
That means that the shell don't find your program in the current directory, or that the python executable can't be found
If your file is there and python works then the "#!/usr/bin/python" must be wrong.
Since you have copied the file from a windows machine, the file will have DOS end of lines (0xd 0xa). Since in linux the eol is 0xA the 0xD character gets appended to the #! line and will cause the interpreter search fail.
You should first run the program through an utility like dos2unix or open it with a text editor able to save it with the right eol (PyGTKEditor for example)

Munk 2008-09-21 01:36

Re: Help with Python please
 
Ooh, maacruz, I like what you are saying as it seems to make sense. I have used nano to edit this file on the NIT but it still doesn't seem to change anything. I'll try looking at the other items you mentioned when I get home later tonight.

Thanks for you advice and any other suggestions would be great.

Munk 2008-09-21 04:27

Re: Help with Python please
 
maacruz,

YOU WERE RIGHT! It was the file being odd to Linux/Python. Using Geany, I copied all the lines of code into a new file, and when I ran it, it worked perfectly the first time. I thought I was going crazy because it should have worked.

Thank you for your insight and help.

Nyrath 2008-09-22 16:00

Re: Help with Python please
 
Yes, the difference between DOS end-of-line and Linux end-of-line is an annoying problem, and still trips me up occasionally.

fatalsaint 2008-09-22 18:01

Re: Help with Python please
 
something like this in VI should fix the newline problem..

:%s/\r//g

or

:%s/^V^M//g

That's Control+V, Control+M

one of these should kill the microsoft newline junk.

renanholanda 2008-12-16 04:42

need help too
 
hi, i am having a bit of trouble myself.. i write the souce code.. save it.. then when i push the run button it opens a terminal and says "press enter" then anything i press closes the window.. i am trying to program straight in the n810 using pyGTKEditor by khertan.. thanks for the help..

bongo 2008-12-16 06:44

Re: need help too
 
Quote:

Originally Posted by renanholanda (Post 249826)
hi, i am having a bit of trouble myself.. i write the souce code.. save it.. then when i push the run button it opens a terminal and says "press enter" then anything i press closes the window.. i am trying to program straight in the n810 using pyGTKEditor by khertan.. thanks for the help..

This happens when your application has no output. Insert a print command and you'll see it in the terminal window.

renanholanda 2008-12-16 22:24

Re: Help with Python please
 
thanks for the help.. but even with print comands or raw_input().. nothing comes up.. just goes 'press enter to continue' its like something is going wrong with the program itself.. it was working fine before i flashed the device.. but I installed the same way.. dont know why it would be any different this time.. maybe its not running python.. maybe the installer did not set the path straight.. or put the program on the wrong folder.. don't know.. any other thoughts??

qwerty12 2008-12-16 22:53

Re: Help with Python please
 
If you have python-launcher installed, you won't see the output. Try running with 'python <.py file>' manually.


All times are GMT. The time now is 06:04.

vBulletin® Version 3.8.8