Search code examples
pythonbashpyinstaller

-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)

Solution

  • 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.