thrinadhn commited on
Commit
1aa6016
·
verified ·
1 Parent(s): d152c02

Create requirement_generation.py

Browse files
Files changed (1) hide show
  1. requirement_generation.py +28 -0
requirement_generation.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import importlib.metadata
2
+
3
+ def create_requirements_file(library_names, output_file='requirements.txt'):
4
+ """
5
+ Generates a requirements.txt file with the installed versions of the specified libraries.
6
+
7
+ Args:
8
+ library_names (list): A list of library names to include in the requirements file.
9
+ output_file (str): The name of the output file. Default is 'requirements.txt'.
10
+ """
11
+ requirements = []
12
+ for lib in library_names:
13
+ try:
14
+ # Get the library's installed version
15
+ version = importlib.metadata.version(lib)
16
+ requirements.append(f"{lib}=={version}")
17
+ except importlib.metadata.PackageNotFoundError:
18
+ print(f"Warning: {lib} is not installed on your system.")
19
+
20
+ # Write the requirements to the file
21
+ with open(output_file, 'w') as file:
22
+ file.write("\n".join(requirements))
23
+
24
+ print(f"Requirements file '{output_file}' has been created successfully!")
25
+
26
+ # Example usage:
27
+ library_list = ['arize-phoenix', 'arize-phoenix-otel', 'openinference-instrumentation-groq', 'groq', 'sentence-transformers', 'pandas', 'python-dotenv', 'streamlit','plotly','litellm'] # Replace with your libraries
28
+ create_requirements_file(library_list)