Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-bash: cannot execute: required file not found

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)
like image 416
maxdu Avatar asked Apr 01 '26 09:04

maxdu


2 Answers

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.

like image 196
Ed Morton Avatar answered Apr 03 '26 21:04

Ed Morton


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)

like image 22
Josh Brunton Avatar answered Apr 03 '26 21:04

Josh Brunton