I have a Python 3.9 script running in a virtual environment. The host environment is set up with Python 3.6 and many installed packages. I need to be able to run a shell script that only functions properly if it's run in the host environment.
It's not possible for me to make the 3.9 virtual environment work for this shell script, nor is it possible to update the shell script to work in Python 3.9.
When I run the script at the command line, I need to call deactivate, run the shell script, and then reactivate the virtual environment.
I'd like to be able to do the equivalent of that from within a Python program running in my 3.9 venv. But since I'm trying to run a shell script and not a Python program, I can't simply call the Python 3.6 interpreter directly to solve the problem.
I can think of two solutions:
- Create a temporary shell script that deactivates the venv and calls the target shell script. Then run that temporary shell script from my Py3.9 program. I assume the deactivation will only apply to the scope I create when I run the shell script.
- Create an alias for every program I want to run that first runs deactivate, e.g.
alias run_myprog = "deactivate; myprog", although it would be kind of tedious to have to create one of these for every program I need to run.
Are there better solutions than the above two?
(This is related to this question. The difference is that question is asking about running a Python 3.6 program instead of a shell script that depends on Python 3.6.)
deactivateis not exported). This being said, does this answer your question? How can I temporary bypass python virtual environment from inside a bash script?