I have a Python script that need to be run with a particular python installation.
Is there a way to craft a shebang so that it runs with $FOO/bar/MyCustomPython?
|
|
||||
|
|
|
The shebang line is very limited. Under many unix variants (including Linux), you can have only two words: a command and a single argument. There is also often a length limitation. The general solution is to write a small shell wrapper. Name the Python script
Another tempting approach is to write a wrapper script like the one above, and put If
Yet another approach is to arrange for the script to be both a valid shell script (which loads the right Python interpreter on itself) and a valid script in the target language (here Python). This requires that you find a way to write such a dual-language script for your target language. In Perl, this is known as
Here's one way to achieve the same effect in Python. In the shell,
Rosetta code has such dual-language scripts in several other languages. |
|||||||||||
|
|
Shebang lines do not undergo variable expansion, so you cannot use An alternative is to have your shebang point to a shell script as the interpreter, and this shell script can then use environment variables to locate the correct one and exec it. Example: create a
then you can use this shebang line to have a Python script executed through
|
|||||
|
|
You can either use the absolute path to the custom python installation, or you can put it in your
|
|||
|
|
|
First, determine how your version of Python is different from the standard Python already installed (for example, an additional module) and then at the start of the program 'switch' how the Python is called:
This should allow the program to be called by any other instance of Python. I do something similar for an instance with built-in sql library that cannot be imported as a module in the system's python. |
|||
|
|
|
If you can replace
Edit: Seems to work only without quotes around the PATH value assignment:
|
|||||
|
