-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall_Setup.py_Project.py
32 lines (25 loc) · 1.52 KB
/
Install_Setup.py_Project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import subprocess
import platform
def find_and_activate_venv():
# Get the current working directory
cwd = os.getcwd()
# Walk through the current directory and its subdirectories
for root, dirs, files in os.walk(cwd):
# Check if the directory contains a virtual environment
if 'Scripts' in dirs or 'bin' in dirs:
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
# Check if the required activation file is present in the Scripts/bin directory
if required_files.issubset(set(os.listdir(scripts_path))):
print(f"Virtual environment found and activated at: {root}")
# Activate the virtual environment and upgrade pip
if platform.system() == 'Windows':
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip && pip install ."'
else:
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
return
print("No virtual environment found.")
if __name__ == "__main__":
find_and_activate_venv()