0

the python executable is "/path/A/B/python". But unfortunately I need to source a file and export some environmental variables to make that executable runnable.

So I want to define my own "interpreter", say /home/name/mypython

#!/bin/bash 
source something
/path/A/B/python

and include above script in the shebang of a python file

#!/home/name/mypython

## rest of the python script

but unfortunately it doesn't work. it just brings me to a python shell without doing anything. what else should I do that?

Vendetta
  • 13,178
  • 19
  • 71
  • 111

1 Answers1

0

Assume:

  • python-script: path/to/my_script.py
  • path to a python_executable: /path/A/B/python
  • a shell script: /home/name/mypython.sh

The way you set it up. the shebang in my_script.py calls mypython.sh which executes the commands of sourcing and than calls a python interpreter with no arguments resulting in the python shell.

add the path of my_script.py to mypython.sh, this way the shebang in my_script.py is ignored

#!/bin/bash 
source something
/path/A/B/python path/to/my_script.py

there is a really good thread how the shebang and python works: Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?

tiennes
  • 69
  • 5