0
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?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Vidare17
  • 45
  • 1
  • 6
  • I guess yours would properly be a duplicate of https://stackoverflow.com/questions/55840939/how-to-fix-cannot-open-file-test-py-errno2-no-such-file-or-directory instead but it doesn't have an upvoted answer. Long story short, don't type `python3 facemorpher` when the script you want to run should be run simply with the command `facemorpher` – tripleee Mar 18 '21 at 12:41
  • AH, indeed, facemorpher --version executes. Thank you for your help! So, should I delete the question, or leave it as is? – Vidare17 Mar 18 '21 at 12:42
  • It seems it could be helpful to reopen the question and add the solution of omitting 'python3' when executing without full path - it is useful info and hard to find the answer to unless you already know it. Especially since examples online execute it with 'python'. The duplicate you've indicated has a very situation-specific title and description, *and* no explanation on how to run the script without the path. Also, this is not a duplicate of what it's marked as atm. – Vidare17 Mar 18 '21 at 14:20

1 Answers1

0

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

tripleee
  • 175,061
  • 34
  • 275
  • 318