Reputation: 531
I have been working with Python for a short while and have created some programs, Im just setting up a third Raspberry Pi with Raspian Jessie. On the other two Pis I didn't run into an issue, but on this one I can't get my Python script to execute the same way.
The first line of the file has the shebang:
#!/usr/bin/env python
I git cloned the repo and went to the directory and did:
chmod +x script.py
but when I try to ./script.py
it doesnt work. From the Desktop it asks if the file should be executed and when I choose execute in terminal it closes and does not execute. I tried placing script.py in
/usr/local/bin
but that has no effect. If I do:
python script.py
it works fine.
The only difference between the Pis is the first two are headless and this new one has the Pixel desktop environment.
Upvotes: 2
Views: 437
Reputation: 227270
You probably made the file on a Windows PC and it got saved with DOS-style line endings. The linux shell (bash) doesn't like that and gets confused when trying to execute the script file.
Try to convert the file to UNIX line endings:
dos2unix script.py
You may need to do apt-get install dos2unix
.
As a tip, you can use an editor/IDE in Windows that supports/saves as UNIX-style line endings to avoid this.
Upvotes: 3