-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathreq.py
49 lines (44 loc) · 1.04 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import subprocess
packages = [
"matplotlib",
"geopandas",
"pandas",
"geoplot",
"pyvista",
"plotly",
"wikipedia",
"lxml",
"nbformat",
"pyfonts",
"drawarrow",
"scikit-learn",
"osmnx",
"highlight_text",
"pypalettes",
"ridge_map",
"seaborn",
"folium",
"cartopy",
"h3",
"h3pandas",
"streamlit",
"watchdog",
]
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.txt", "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}")