Created
April 13, 2023 08:14
-
-
Save Kludex/70a13ecbe62161205822ea3375607aec to your computer and use it in GitHub Desktop.
Create a virtual environment, and run a different python process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Create a virtual environment, and run a different python process.""" | |
import os | |
import subprocess | |
import tempfile | |
import venv | |
with tempfile.TemporaryDirectory() as temp_dir: | |
VENV_PATH = os.path.join(temp_dir, "venv") | |
venv.create(VENV_PATH, with_pip=True) | |
python_exe = os.path.join(VENV_PATH, "bin", "python") | |
subprocess.call([python_exe, "--version"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment