I want to use a .sh file as a wrapper for executing Python because I need to import specific environment variables before running my Python scripts. The structure of my .sh file (my_python.sh) looks like this:
SCRIPT_DIR=some_path
export PATH1=some_path_2
source another_script.sh
python_exe=${PYTHONEXE:-"${SCRIPT_DIR}/kit/python/bin/python3"}
$python_exe "$@" $args || error_exit
I can successfully run Python scripts by executing this .sh file directly in the terminal, e.g.:
./my_python.sh my_script.py
This works fine, as the necessary environment variables are sourced before script execution.
However, when I try to set this wrapper script my_python.sh as the Python interpreter in VS Code using "Enter interpreter path", VS Code instead selects the python_exe (the resolved path to python3) directly. This bypasses the .sh script, so the required environment variables aren't imported, and the execution of my_script.py fails.
Is there a way to configure VS Code to use the .sh script as if it was the Python interpreter so that it correctly sources the environment variables? I believe it is possible because my colleague could make it work, but we could not figure out the differences between our setups. My VS Code version is 1.95.3.
I tried reinstalling VS Code, changed the location of the .sh file. The only workaround I found was to define the environment variables in a launch.json but this solution does not seem to be scalable.
.bashrcor equivalent? Or do you need different environment variables for different projects?