-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup_env.py
More file actions
40 lines (32 loc) · 1.24 KB
/
setup_env.py
File metadata and controls
40 lines (32 loc) · 1.24 KB
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
33
34
35
36
37
38
39
40
import os
import subprocess
import sys
def check_and_install_packages():
# Install remaining packages from requirements.txt without printing "Requirement already satisfied"
try:
subprocess.check_call(
[f"{venv_dir}/Scripts/python" if os.name == "nt" else f"{venv_dir}/bin/python",
"-m", "pip", "install", "--quiet", "-r", "requirements.txt"]
)
except subprocess.CalledProcessError as e:
sys.exit(f"Error installing packages: {e}")
def create_venv():
global venv_dir
venv_dir = "venv"
if not os.path.exists(venv_dir):
# Create virtual environment
subprocess.check_call([sys.executable, "-m", "venv", venv_dir])
print(f"Virtual environment created at {venv_dir}")
else:
print(f"Virtual environment already exists at {venv_dir}")
check_and_install_packages()
def main():
create_venv()
# Print activation instructions
if os.name == "nt":
print(f"To activate the environment, run:\n{venv_dir}\\Scripts\\activate")
else:
print(f"To activate the environment, run:\nsource {venv_dir}/bin/activate")
print("Virtual environment setup complete. Now you can activate it manually.")
if __name__ == "__main__":
main()