I have a Python 3.6 script that calls out to a third-party tool using subprocess.
main_script.py:
#!/usr/bin/env python
import subprocess
result = subprocess.run(['third-party-tool', '-arg1'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
The problem is, main_script.py
must be run from within a virtual environment, and third-party-tool
must be run from no virtual environment whatsoever.
I don't know much about third-party-tool
, except that it is on my path. Calling it while I have a virtual environment active causes it to jam up and throw an exception later on. I do not know if it uses the default python binary or it it spins up its own virtual env and does stuff in there. It is not a Python script, but apparently calls one somehow.
How do I tell subprocess to drop out of my virtual environment and run the command in the default shell environment?
I've examined a couple of similar questions:
- Running subprocess within different virtualenv with python -- In the first case, they are specifying the environment by calling their script with a specific version of Python.
third-party-tool
is not a Python script (I believe it's bash). - Python subprocess/Popen with a modified environment -- In the second case, they're tweaking existing environment variables, which looks promising, but I want to reset to the default environment, and I'm not sure if I necessarily know which variables I need to clear or reset.