INNER CODE UNIT · Python
create_with_virtualenv
devstream-io/devstream · devstream/env_manager.py:133
def create_with_virtualenv(self, env_name: str) -> Tuple[bool, str]:
"""
Create a new python environment using virtualenv with the current Python interpreter.
"""
env_path = os.path.join(MAMBA_PY_ENVS, env_name)
if os.path.exists(env_path):
return True, ""
try:
# Use virtualenv.cli_run to create a virtual environment
virtualenv.cli_run([env_path, "--python", sys.executable])
# Create sitecustomize.py in the lib/site-packages directory
site_packages_dir = os.path.join(env_path, "Lib", "site-packages")
if os.path.exists(site_packages_dir):
sitecustomize_path = os.path.join(site_packages_dir, "sitecustomize.py")
with open(sitecustomize_path, "w") as f:
f.write("import sys\n")