DanneA
Posts: 11
Joined: Wed Nov 05, 2014 7:36 pm
Location: Thailand

Try to run a Python script without luck...

Thu Nov 22, 2018 9:10 am

Help! I do not understand what is going on...

I do not get it to work, for me, by an unknown reason!?
I am superuser mode and in the /root directory, where even
the program file "check_ip.py" is.

root@Pi-server:~# pwd
/root
root@Pi-server:~# ls -alh
total 64K
drwx------ 3 root root 4.0K Nov 22 15:41 .
drwxr-xr-x 23 root root 4.0K Nov 17 11:35 ..
-rw------- 1 root root 2.0K Nov 22 14:41 .bash_history
-rw-r--r-- 1 root root 570 Mar 12 2018 .bashrc
-rwx------ 1 root root 25K Nov 22 13:15 check_ip.py
drwxr-xr-x 2 root root 4.0K Nov 10 15:49 .nano
-rwx------ 1 root root 482 Nov 20 16:11 open_vpn_firewall.sh
-rw-r--r-- 1 root root 148 Mar 12 2018 .profile
-rw------- 1 root root 1.0K Nov 20 15:11 .rnd
-rw------- 1 root root 810 Nov 20 18:22 .viminfo

If I follow the instruction from the book, I should test to
run the Python program with the command under here:

root@Pi-server:~# ./check_ip.py -e

But it answer me with this

bash: ./check_ip.py: /usr/bin/python^M: bad interpreter: No such file or directory
root@Pi-server:~#

I just do not understand what it answer me with the bash-line?!
I have get Python 3.5 installed and I understand that Python interpret
line buy line.
And in the drawer /usr/bin is a lot of Python... :?:

It is like a snake farm... :lol:

It is not easy to be an old newbee, but I learn slowly, slowly...
DanneA

jahboater
Posts: 4769
Joined: Wed Feb 04, 2015 6:38 pm

Re: Try to run a Python script without luck...

Thu Nov 22, 2018 9:35 am

DanneA wrote:
Thu Nov 22, 2018 9:10 am

root@Pi-server:~# ./check_ip.py -e

But it answer me with this

bash: ./check_ip.py: /usr/bin/python^M: bad interpreter: No such file or directory
root@Pi-server:~#
Looks like you have edited or created the "check_ip.py" file on Windows?

Text lines on UNIX/Linux/MacOS end in a single LF (Line Feed) character.
Windows still uses the old CR LF line separator (Carriage Return followed by Line Feed) and ^M is CR.

sudo apt install dos2unix
man dos2unix

Its also a bad idea to work in /root !!!
In general, avoid using the root user-id or sudo.

DanneA
Posts: 11
Joined: Wed Nov 05, 2014 7:36 pm
Location: Thailand

Re: Try to run a Python script without luck...

Thu Nov 22, 2018 10:02 am

jahboater wrote:
Thu Nov 22, 2018 9:35 am
DanneA wrote:
Thu Nov 22, 2018 9:10 am

root@Pi-server:~# ./check_ip.py -e

But it answer me with this

bash: ./check_ip.py: /usr/bin/python^M: bad interpreter: No such file or directory
root@Pi-server:~#
Looks like you have edited or created the "check_ip.py" file on Windows?

Text lines on UNIX/Linux/MacOS end in a single LF (Line Feed) character.
Windows still uses the old CR LF line separator (Carriage Return followed by Line Feed) and ^M is CR.

sudo apt install dos2unix
man dos2unix

Its also a bad idea to work in /root !!!
In general, avoid using the root user-id or sudo.

Hello!
Maybe yes!
I downloaded the script from a webpage and changed it in Notpad++
after that i loaded it to the Pi with NppFTP straight from Notpad++ in
to the Pi.

Then I changed some lines in nano. That does not work then?!

DanneA

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23891
Joined: Sat Jul 30, 2011 7:41 pm

Re: Try to run a Python script without luck...

Thu Nov 22, 2018 10:06 am

DanneA wrote:
Thu Nov 22, 2018 10:02 am
jahboater wrote:
Thu Nov 22, 2018 9:35 am
DanneA wrote:
Thu Nov 22, 2018 9:10 am

root@Pi-server:~# ./check_ip.py -e

But it answer me with this

bash: ./check_ip.py: /usr/bin/python^M: bad interpreter: No such file or directory
root@Pi-server:~#
Looks like you have edited or created the "check_ip.py" file on Windows?

Text lines on UNIX/Linux/MacOS end in a single LF (Line Feed) character.
Windows still uses the old CR LF line separator (Carriage Return followed by Line Feed) and ^M is CR.

sudo apt install dos2unix
man dos2unix

Its also a bad idea to work in /root !!!
In general, avoid using the root user-id or sudo.

Hello!
Maybe yes!
I downloaded the script from a webpage and changed it in Notpad++
after that i loaded it to the Pi with NppFTP straight from Notpad++ in
to the Pi.

Then I changed some lines in nano. That does not work then?!

DanneA
You can make Notepad++ save files with Unix line endings - that's probably the best option.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

User avatar
Mortimer
Posts: 923
Joined: Sun Jun 10, 2012 3:57 pm

Re: Try to run a Python script without luck...

Thu Nov 22, 2018 10:17 am

Yup, had to do a similar thing just a few minutes ago whilst writing a shell script to run on an ESXi server in Notepad++.

With the file open, select "Edit" > "EOL Conversion" > "Unix (LF)".
I believe Notepad++ will remember that setting for the file, so it shouldn't be necessary to do that again for that file.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

User avatar
Mortimer
Posts: 923
Joined: Sun Jun 10, 2012 3:57 pm

Re: Try to run a Python script without luck...

Thu Nov 22, 2018 10:49 am

Alternatively, if you're using WinSCP to copy the file to the RPi, the conversion will be done there too, but you may need to make sure the transfer mode is set to "Text", or if it is set to "Automatic" that the "Transfer following files in text mode:" field contains the file extensions for the files you want converted.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

hippy
Posts: 6089
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Try to run a Python script without luck...

Thu Nov 22, 2018 2:52 pm

If one runs a Python program with the usual "python myfile.py" command ( with appropriate path specifications for each as required ), the interpreter won't care whether the program has Windows or Linux line endings.

That's one of the things which makes Python so nice for cross-platform development. Just set up Samba and drag and drop programs from Windows onto the Pi and they will run.

Return to “Troubleshooting”