Skip to content

Commit 937e770

Browse files
authored
Add files via upload
1 parent d1d90d0 commit 937e770

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Diff for: Create_WSL_Python3.12_VirtualEnv_.venv.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Script Developer: Gabriel Mihai Sandu
2+
# GitHub Profile: https://github.com/Gabrieliam42
3+
4+
import os
5+
import subprocess
6+
import sys
7+
8+
def is_wsl():
9+
try:
10+
with open("/proc/version", "r") as f:
11+
return "microsoft" in f.read().lower()
12+
except FileNotFoundError:
13+
return False
14+
15+
def create_virtualenv():
16+
# Use the Linux native home directory
17+
home_dir = os.path.expanduser("~")
18+
venv_path = os.path.join(home_dir, ".venv")
19+
20+
# Modified command to use /usr/bin/python3.10 with --system-site-packages
21+
command = f"/usr/bin/python3.12 -m venv --system-site-packages {venv_path}"
22+
23+
try:
24+
print(f"Creating virtual environment at: {venv_path}")
25+
subprocess.run(command, shell=True, check=True)
26+
print("Virtual environment '.venv' created successfully.")
27+
28+
print("\nThe virtual environment is activated!")
29+
shell = os.environ.get("SHELL", "/bin/bash")
30+
subprocess.run(f"exec {shell} --rcfile {venv_path}/bin/activate", shell=True)
31+
32+
except subprocess.CalledProcessError as e:
33+
print(f"Error while creating virtual environment: {e}")
34+
sys.exit(1)
35+
36+
if __name__ == "__main__":
37+
if not is_wsl():
38+
print("This script must be run inside WSL2. Exiting...")
39+
sys.exit(1)
40+
41+
create_virtualenv()

0 commit comments

Comments
 (0)