0

I would like to create the target python3 to be used in shebangs. Eg. use the first line #!/usr/bin/env python3.

What I tried:

  • setenv python3 PATH_TO_BINARY, also put it into .cshrc, echo $python3 shows also path

  • /bin/env NAME=python3 PATH_TO_BINARY, opens python3 but doesn't allow usage of the shebang. The same for /bin/env python3=PATH_TO_BINARY

In case it matters, I would like to solve the following problem:

I'm working on a rhel 6 system were I cannot directly install python3 however I can used it over anaconda3 which is installed at an accessible network resource. Instead of putting the shebang with the absolute path I would like to properly set the python3 path write portable code.

1 Answer 1

2

In this case, it's not the #!-line you should be changing, but your $PATH.

#!/usr/bin/env python3

This has the effect that the python3 interpreter will be searched for in the directories listed in your $PATH variable.

If python3 is installed in, e.g., $HOME/local/bin, then this directory must be present in $PATH before any other directory that may also contain a python3 interpreter, otherwise that one will be used instead of your own in $HOME/local/bin.

So you need to set

PATH="$HOME/local/bin:$PATH"

Either on the command line, or in a shell initialization script (~/.bashrc for example). C-shell users do it differently...

set path = ($HOME/local/bin $path)

In general, the #!-line identifies the interpreter for the script, i.e. what program to use to parse and run the file. A sed script, for example, may use #!/usr/bin/sed -f.

1
  • That was it. Thanks for answering my question even though I actually asked the wrong one.
    – magu_
    Commented Jun 17, 2016 at 22:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .