Skip to content

Instantly share code, notes, and snippets.

@Kludex
Created April 13, 2023 08:14
Show Gist options
  • Save Kludex/70a13ecbe62161205822ea3375607aec to your computer and use it in GitHub Desktop.
Save Kludex/70a13ecbe62161205822ea3375607aec to your computer and use it in GitHub Desktop.
Create a virtual environment, and run a different python process.
"""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