Skip to content

Commit f299b05

Browse files
authored
Add files via upload
1 parent 431b8de commit f299b05

9 files changed

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

Create_Python3.10_VirtualEnv_.venv.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Script Developer: Gabriel Mihai Sandu
2+
# GitHub Profile: https://github.com/Gabrieliam42
3+
4+
import os
5+
import subprocess
6+
import platform
7+
import winreg
8+
import ctypes
9+
import sys
10+
import re
11+
12+
def is_admin():
13+
try:
14+
return ctypes.windll.shell32.IsUserAnAdmin()
15+
except:
16+
return False
17+
18+
def run_as_admin():
19+
params = " ".join([f'"{arg}"' for arg in sys.argv])
20+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
21+
22+
def get_python_versions(base_path):
23+
python_versions = []
24+
for folder in os.listdir(base_path):
25+
match = re.match(r'^Python(\d{3})$', folder)
26+
if match and match.group(1) != '310':
27+
python_versions.append(folder)
28+
return python_versions
29+
30+
def update_environment_variable(variable_name, new_value, scope):
31+
try:
32+
with winreg.OpenKey(scope, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg.KEY_ALL_ACCESS) as key:
33+
value, regtype = winreg.QueryValueEx(key, variable_name)
34+
value_list = value.split(os.pathsep)
35+
# Remove any existing instances of the new value
36+
value_list = [v for v in value_list if v != new_value]
37+
# Add the new value to the top
38+
value_list.insert(0, new_value)
39+
new_value_str = os.pathsep.join(value_list)
40+
winreg.SetValueEx(key, variable_name, 0, regtype, new_value_str)
41+
print(f"Updated {variable_name} in system variables.")
42+
except FileNotFoundError:
43+
print(f"{variable_name} not found in system variables.")
44+
45+
def create_virtual_environment(directory):
46+
print(f"Creating a virtual environment in {directory}...")
47+
subprocess.run(["python", "-m", "venv", ".venv"], cwd=directory, shell=True)
48+
print("Virtual environment created.")
49+
50+
def find_and_activate_venv():
51+
cwd = os.getcwd()
52+
for root, dirs, files in os.walk(cwd):
53+
if 'Scripts' in dirs or 'bin' in dirs:
54+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
55+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
56+
if required_files.issubset(set(os.listdir(scripts_path))):
57+
print(f"Virtual environment found and activated at: {root}")
58+
if platform.system() == 'Windows':
59+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
60+
else:
61+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
62+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
63+
return
64+
print("No virtual environment found.")
65+
66+
if __name__ == "__main__":
67+
if not is_admin():
68+
print("Requesting administrative privileges...")
69+
run_as_admin()
70+
sys.exit()
71+
72+
base_path = r"C:\Program Files"
73+
new_path = r"C:\Program Files\Python310"
74+
new_path_scripts = os.path.join(new_path, 'Scripts')
75+
76+
update_environment_variable('Path', new_path_scripts, winreg.HKEY_LOCAL_MACHINE)
77+
update_environment_variable('Path', new_path, winreg.HKEY_LOCAL_MACHINE)
78+
79+
print("All changes to the System and User Variables have been made!")
80+
create_virtual_environment(os.getcwd())
81+
find_and_activate_venv()
82+
83+
if platform.system() == 'Windows':
84+
subprocess.run(['cmd', '/k', 'echo Virtual environment setup complete.'], shell=True)
7.63 MB
Binary file not shown.

Create_Python3.11_VirtualEnv_.venv.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Script Developer: Gabriel Mihai Sandu
2+
# GitHub Profile: https://github.com/Gabrieliam42
3+
4+
import os
5+
import subprocess
6+
import platform
7+
import winreg
8+
import ctypes
9+
import sys
10+
import re
11+
12+
def is_admin():
13+
try:
14+
return ctypes.windll.shell32.IsUserAnAdmin()
15+
except:
16+
return False
17+
18+
def run_as_admin():
19+
params = " ".join([f'"{arg}"' for arg in sys.argv])
20+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
21+
22+
def get_python_versions(base_path):
23+
python_versions = []
24+
for folder in os.listdir(base_path):
25+
match = re.match(r'^Python(\d{3})$', folder)
26+
if match and match.group(1) != '311':
27+
python_versions.append(folder)
28+
return python_versions
29+
30+
def update_environment_variable(variable_name, new_value, scope):
31+
try:
32+
with winreg.OpenKey(scope, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg.KEY_ALL_ACCESS) as key:
33+
value, regtype = winreg.QueryValueEx(key, variable_name)
34+
value_list = value.split(os.pathsep)
35+
# Remove any existing instances of the new value
36+
value_list = [v for v in value_list if v != new_value]
37+
# Add the new value to the top
38+
value_list.insert(0, new_value)
39+
new_value_str = os.pathsep.join(value_list)
40+
winreg.SetValueEx(key, variable_name, 0, regtype, new_value_str)
41+
print(f"Updated {variable_name} in system variables.")
42+
except FileNotFoundError:
43+
print(f"{variable_name} not found in system variables.")
44+
45+
def create_virtual_environment(directory):
46+
print(f"Creating a virtual environment in {directory}...")
47+
subprocess.run(["python", "-m", "venv", ".venv"], cwd=directory, shell=True)
48+
print("Virtual environment created.")
49+
50+
def find_and_activate_venv():
51+
cwd = os.getcwd()
52+
for root, dirs, files in os.walk(cwd):
53+
if 'Scripts' in dirs or 'bin' in dirs:
54+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
55+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
56+
if required_files.issubset(set(os.listdir(scripts_path))):
57+
print(f"Virtual environment found and activated at: {root}")
58+
if platform.system() == 'Windows':
59+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
60+
else:
61+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
62+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
63+
return
64+
print("No virtual environment found.")
65+
66+
if __name__ == "__main__":
67+
if not is_admin():
68+
print("Requesting administrative privileges...")
69+
run_as_admin()
70+
sys.exit()
71+
72+
base_path = r"C:\Program Files"
73+
new_path = r"C:\Program Files\Python311"
74+
new_path_scripts = os.path.join(new_path, 'Scripts')
75+
76+
update_environment_variable('Path', new_path_scripts, winreg.HKEY_LOCAL_MACHINE)
77+
update_environment_variable('Path', new_path, winreg.HKEY_LOCAL_MACHINE)
78+
79+
print("All changes to the System and User Variables have been made!")
80+
create_virtual_environment(os.getcwd())
81+
find_and_activate_venv()
82+
83+
if platform.system() == 'Windows':
84+
subprocess.run(['cmd', '/k', 'echo Virtual environment setup complete.'], shell=True)
7.86 MB
Binary file not shown.

Create_Python3.12_VirtualEnv_.venv.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Script Developer: Gabriel Mihai Sandu
2+
# GitHub Profile: https://github.com/Gabrieliam42
3+
4+
import os
5+
import subprocess
6+
import platform
7+
import winreg
8+
import ctypes
9+
import sys
10+
import re
11+
12+
def is_admin():
13+
try:
14+
return ctypes.windll.shell32.IsUserAnAdmin()
15+
except:
16+
return False
17+
18+
def run_as_admin():
19+
params = " ".join([f'"{arg}"' for arg in sys.argv])
20+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
21+
22+
def get_python_versions(base_path):
23+
python_versions = []
24+
for folder in os.listdir(base_path):
25+
match = re.match(r'^Python(\d{3})$', folder)
26+
if match and match.group(1) != '312':
27+
python_versions.append(folder)
28+
return python_versions
29+
30+
def update_environment_variable(variable_name, new_value, scope):
31+
try:
32+
with winreg.OpenKey(scope, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg.KEY_ALL_ACCESS) as key:
33+
value, regtype = winreg.QueryValueEx(key, variable_name)
34+
value_list = value.split(os.pathsep)
35+
# Remove any existing instances of the new value
36+
value_list = [v for v in value_list if v != new_value]
37+
# Add the new value to the top
38+
value_list.insert(0, new_value)
39+
new_value_str = os.pathsep.join(value_list)
40+
winreg.SetValueEx(key, variable_name, 0, regtype, new_value_str)
41+
print(f"Updated {variable_name} in system variables.")
42+
except FileNotFoundError:
43+
print(f"{variable_name} not found in system variables.")
44+
45+
def create_virtual_environment(directory):
46+
print(f"Creating a virtual environment in {directory}...")
47+
subprocess.run(["python", "-m", "venv", ".venv"], cwd=directory, shell=True)
48+
print("Virtual environment created.")
49+
50+
def find_and_activate_venv():
51+
cwd = os.getcwd()
52+
for root, dirs, files in os.walk(cwd):
53+
if 'Scripts' in dirs or 'bin' in dirs:
54+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
55+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
56+
if required_files.issubset(set(os.listdir(scripts_path))):
57+
print(f"Virtual environment found and activated at: {root}")
58+
if platform.system() == 'Windows':
59+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
60+
else:
61+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
62+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
63+
return
64+
print("No virtual environment found.")
65+
66+
if __name__ == "__main__":
67+
if not is_admin():
68+
print("Requesting administrative privileges...")
69+
run_as_admin()
70+
sys.exit()
71+
72+
base_path = r"C:\Program Files"
73+
new_path = r"C:\Program Files\Python312"
74+
new_path_scripts = os.path.join(new_path, 'Scripts')
75+
76+
update_environment_variable('Path', new_path_scripts, winreg.HKEY_LOCAL_MACHINE)
77+
update_environment_variable('Path', new_path, winreg.HKEY_LOCAL_MACHINE)
78+
79+
print("All changes to the System and User Variables have been made!")
80+
create_virtual_environment(os.getcwd())
81+
find_and_activate_venv()
82+
83+
if platform.system() == 'Windows':
84+
subprocess.run(['cmd', '/k', 'echo Virtual environment setup complete.'], shell=True)
7.84 MB
Binary file not shown.

Create_Python3.13_VirtualEnv_.venv.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Script Developer: Gabriel Mihai Sandu
2+
# GitHub Profile: https://github.com/Gabrieliam42
3+
4+
import os
5+
import subprocess
6+
import platform
7+
import winreg
8+
import ctypes
9+
import sys
10+
import re
11+
12+
def is_admin():
13+
try:
14+
return ctypes.windll.shell32.IsUserAnAdmin()
15+
except:
16+
return False
17+
18+
def run_as_admin():
19+
params = " ".join([f'"{arg}"' for arg in sys.argv])
20+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
21+
22+
def get_python_versions(base_path):
23+
python_versions = []
24+
for folder in os.listdir(base_path):
25+
match = re.match(r'^Python(\d{3})$', folder)
26+
if match and match.group(1) != '313':
27+
python_versions.append(folder)
28+
return python_versions
29+
30+
def update_environment_variable(variable_name, new_value, scope):
31+
try:
32+
with winreg.OpenKey(scope, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg.KEY_ALL_ACCESS) as key:
33+
value, regtype = winreg.QueryValueEx(key, variable_name)
34+
value_list = value.split(os.pathsep)
35+
# Remove any existing instances of the new value
36+
value_list = [v for v in value_list if v != new_value]
37+
# Add the new value to the top
38+
value_list.insert(0, new_value)
39+
new_value_str = os.pathsep.join(value_list)
40+
winreg.SetValueEx(key, variable_name, 0, regtype, new_value_str)
41+
print(f"Updated {variable_name} in system variables.")
42+
except FileNotFoundError:
43+
print(f"{variable_name} not found in system variables.")
44+
45+
def create_virtual_environment(directory):
46+
print(f"Creating a virtual environment in {directory}...")
47+
subprocess.run(["python", "-m", "venv", ".venv"], cwd=directory, shell=True)
48+
print("Virtual environment created.")
49+
50+
def find_and_activate_venv():
51+
cwd = os.getcwd()
52+
for root, dirs, files in os.walk(cwd):
53+
if 'Scripts' in dirs or 'bin' in dirs:
54+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
55+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
56+
if required_files.issubset(set(os.listdir(scripts_path))):
57+
print(f"Virtual environment found and activated at: {root}")
58+
if platform.system() == 'Windows':
59+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
60+
else:
61+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
62+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
63+
return
64+
print("No virtual environment found.")
65+
66+
if __name__ == "__main__":
67+
if not is_admin():
68+
print("Requesting administrative privileges...")
69+
run_as_admin()
70+
sys.exit()
71+
72+
base_path = r"C:\Program Files"
73+
new_path = r"C:\Program Files\Python313"
74+
new_path_scripts = os.path.join(new_path, 'Scripts')
75+
76+
update_environment_variable('Path', new_path_scripts, winreg.HKEY_LOCAL_MACHINE)
77+
update_environment_variable('Path', new_path, winreg.HKEY_LOCAL_MACHINE)
78+
79+
print("All changes to the System and User Variables have been made!")
80+
create_virtual_environment(os.getcwd())
81+
find_and_activate_venv()
82+
83+
if platform.system() == 'Windows':
84+
subprocess.run(['cmd', '/k', 'echo Virtual environment setup complete.'], shell=True)

0 commit comments

Comments
 (0)