I am having multiple problems with making my pythonscript dartsapp.py executable for my pi.
At first i tried to use
chmod +x dartsapp.py
and
./dartsapp.py
but i got the error:
-bash: ./dartsapp.py: cannot execute: required file not found
I also added the dir to PATH but still no luck. Afterwards i tried to use pyinstaller but when i try to call
pyinstaller --version
i get the same
-bash: pyinstaller: command not found
even though my PATH looks like this:
maxdu@LEDpi:~/0306 $ echo $PATH
/home/maxdu/0306:/home/maxdu/0306/dartsapp.py:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
What am i missing / doing wrong here?
Update:
ls -l /usr/bin/python3
gives me
lrwxrwxrwx 1 root root 10 Apr 9 2023 /usr/bin/python3 -> python3.11
and
head -n 3 dartsapp.py | cat -e
gives me
#!/usr/bin/python3^M$
^M$
# Python-App fM-CM-<r das PunktezM-CM-$hlen beim Darts^M$
and
type python3
gives me
python3 is hashed (/usr/bin/python3)
head -n 3 dartsapp.py | cat -e
outputs:
#!/usr/bin/python3^M$
^M$
# Python-App fM-CM-<r das PunktezM-CM-$hlen beim Darts^M$
and so those ^Ms at the end of each line tells us that dartsapp.py has DOS line endings, see linux-bash-shell-script-error-cannot-execute-required-file-not-found for more information on this specific error and Why does my tool output overwrite itself and how do I fix it? for more information on DOS line endings in general. Both of those questions contain various fixes for this problem, starting with running dos2unix dartsapp.py.
To run dartsapp.py with the python interpreter: You might find some success with this command:
python3 ./dartsapp.py
Unlike shell scripts (typically ending in .sh or no extension), which can be executed so long as you have permission to do so, you'll need to use the python command to execute a python script. python3 comes as standard with most modern linux installations, so this should work on a raspberry pi as well as your dev machine.
To turn dartsapp.py into a self-contained executable using pyinstaller: If you're dead-set on having a self-contained executable, you'll need to install pyinstaller using pip:
python3 -m pip install pyinstaller
And then call pyinstaller on the file:
python3 -m pyinstaller dartsapp.py
(There's a lot more than just that to pyinstaller - see the manual - but you shouldn't really need it to get your program running)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With