Skip to content

Commit bb3e6c5

Browse files
authoredFeb 4, 2025
Update Find_Python_Virtual_Env_and_Activate.py
1 parent 7130884 commit bb3e6c5

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed
 

‎Find_Python_Virtual_Env_and_Activate.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1+
# Script Developer: Gabriel Mihai Sandu
2+
# GitHub Profile: https://github.com/Gabrieliam42
3+
14
import os
25
import subprocess
36
import platform
47

58
def find_and_activate_venv():
6-
# Get the current working directory
79
cwd = os.getcwd()
810

9-
# Walk through the current directory and its subdirectories
1011
for root, dirs, files in os.walk(cwd):
11-
# Check if the directory contains a virtual environment
1212
if 'Scripts' in dirs or 'bin' in dirs:
1313
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
1414
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
1515

16-
# Check if the required activation file is present in the Scripts/bin directory
1716
if required_files.issubset(set(os.listdir(scripts_path))):
1817
print(f"Virtual environment found and activated at: {root}")
1918

20-
# Activate the virtual environment and upgrade pip
2119
if platform.system() == 'Windows':
2220
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
2321
else:

0 commit comments

Comments
 (0)
Please sign in to comment.