|
6 | 6 | import sys
|
7 | 7 |
|
8 | 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 |
| 9 | + try: |
| 10 | + with open("/proc/version", "r") as f: |
| 11 | + return "microsoft" in f.read().lower() |
| 12 | + except FileNotFoundError: |
| 13 | + return False |
14 | 14 |
|
15 | 15 | def create_virtualenv():
|
16 |
| - cwd = os.getcwd() |
17 |
| - venv_path = os.path.join(cwd, ".venv") |
18 |
| - |
19 |
| - command = f"python3.11 -m venv {venv_path}" |
20 |
| - |
21 |
| - try: |
22 |
| - print(f"Creating virtual environment at: {venv_path}") |
23 |
| - subprocess.run(command, shell=True, check=True) |
24 |
| - print(f"Virtual environment '.venv' created successfully in {cwd}.") |
25 |
| - |
26 |
| - print("\nThe virtual environment is activated!") |
| 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.11 -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) |
27 | 31 |
|
28 |
| - shell = os.environ.get("SHELL", "/bin/bash") |
29 |
| - subprocess.run(f"exec {shell} --rcfile {venv_path}/bin/activate", shell=True) |
30 |
| - |
31 |
| - except subprocess.CalledProcessError as e: |
32 |
| - print(f"Error while creating virtual environment: {e}") |
33 |
| - sys.exit(1) |
| 32 | + except subprocess.CalledProcessError as e: |
| 33 | + print(f"Error while creating virtual environment: {e}") |
| 34 | + sys.exit(1) |
34 | 35 |
|
35 | 36 | if __name__ == "__main__":
|
36 |
| - if not is_wsl(): |
37 |
| - print("This script must be run inside WSL2. Exiting...") |
38 |
| - sys.exit(1) |
39 |
| - |
40 |
| - create_virtualenv() |
| 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