-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreq.py
26 lines (21 loc) · 768 Bytes
/
req.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
import subprocess
packages = ["imageio", "numpy", "Pillow"]
REQUIREMENTS_FILE = "requirements.txt"
def get_package_version(package_name: str) -> str:
result = subprocess.run(
["pip", "show", package_name], capture_output=True, text=True
)
details = result.stdout.split("\n")
for line in details:
if line.startswith("Version: "):
return line.split(" ")[1]
return None
with open(REQUIREMENTS_FILE, "w") as file:
for package in packages:
version = get_package_version(package)
if version:
packageVersion = f"{package}=={version}"
print(packageVersion)
file.write(packageVersion + "\n")
else:
print(f"Version not found for package {package}")