简体   繁体   中英

script is on PATH, yet python3 script fails: no such file or directory

dag@Arokh:~$ source /home/dag/.bashrc
dag@Arokh:~$ echo $PATH
/home/dag/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
dag@Arokh:~$ python3 /home/dag/.local/bin/facemorpher --version
Face Morpher 1.0
dag@Arokh:~$ python3 facemorpher --version
python3: can't open file 'facemorpher': [Errno 2] No such file or directory

Adding the directory to PATH doesn't seem to help. How can I make python3 facemorpher work from any directory?

python3 pays no attention to the PATH variable when looking for scripts. This variable controls where the shell looks for executables.

So what should work now, provided the script has executable permissions and a valid shebang like #!/usr/bin/env python3 as its very first line, is that simply

facemorpher

without python3 in front should run the script. Perhaps this is actually what you want and need.

The python3 command without any options expects a file name parameter; there is no simple way to make it look for a file which doesn't exist in the specified directory (which is the current working directory if the filename doesn't have an explicit directory part; this is how the operating system resolves relative file names, and should probably not be messed with for an individual command). For further details about this, perhaps see also Difference between ./ and ~/

For the record, chmod a+x path/to/scriptname adds execute permission to the script for all users on the system, and the path in the shebang after #!should point to your Python interpreter's full path, or the full path to a utility like env which finds it on your PATH and executes it based on just the command name (here, python3 ; but on some systems, the Python interpreter executable's file name is just python , or more broadly whatever the system's owner decided to name it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM