forked from avico78/total_compare
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_req_file.py
More file actions
23 lines (18 loc) · 905 Bytes
/
generate_req_file.py
File metadata and controls
23 lines (18 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import subprocess
import sys
def generate_requirements_file(output_file="requirements.txt"):
try:
# Use pip freeze to get the list of installed packages and their versions
result = subprocess.run([sys.executable, "-m", "pip", "freeze"], capture_output=True, text=True, check=True)
installed_packages = result.stdout.split("\n")
# Write the Python version as a comment
with open(output_file, "w") as file:
file.write(f"# Python {sys.version}\n")
# Write the packages to the requirements.txt file
for package in installed_packages:
file.write(package + "\n")
print(f"Requirements file '{output_file}' generated successfully.")
except subprocess.CalledProcessError as e:
print(f"Error while generating requirements file: {e}")
if __name__ == "__main__":
generate_requirements_file()