2025-04-09 00:53:16 +01:00
|
|
|
import subprocess
|
|
|
|
|
import re
|
2025-02-06 20:22:43 +00:00
|
|
|
|
2025-04-09 00:53:16 +01:00
|
|
|
# List of packages you want to include
|
|
|
|
|
packages = [
|
|
|
|
|
"openai",
|
|
|
|
|
"pandas",
|
|
|
|
|
"python-dotenv",
|
|
|
|
|
"fastapi",
|
|
|
|
|
"uvicorn",
|
|
|
|
|
"langchain-community",
|
|
|
|
|
"langchain-openai",
|
|
|
|
|
"pydantic",
|
|
|
|
|
"pypdf",
|
|
|
|
|
"pypandoc",
|
|
|
|
|
"plum-dispatch==1.7.4", # You specified exact version here
|
|
|
|
|
"scikit-learn",
|
|
|
|
|
"werkzeug",
|
|
|
|
|
"python-multipart",
|
|
|
|
|
"langgraph",
|
|
|
|
|
"tiktoken",
|
|
|
|
|
"langchainhub",
|
|
|
|
|
"chromadb",
|
|
|
|
|
"langchain",
|
|
|
|
|
"langchain-text-splitters",
|
|
|
|
|
"beautifulsoup4",
|
|
|
|
|
"langchain-core",
|
|
|
|
|
"PyPDF2",
|
|
|
|
|
"reportlab",
|
|
|
|
|
"python-docx"
|
|
|
|
|
]
|
2025-02-06 20:22:43 +00:00
|
|
|
|
2025-04-09 00:53:16 +01:00
|
|
|
# Get all installed packages with versions
|
|
|
|
|
result = subprocess.run(["pip", "freeze"], capture_output=True, text=True)
|
|
|
|
|
installed_packages = result.stdout.strip().split('\n')
|
2025-02-12 00:12:02 +01:00
|
|
|
|
2025-04-09 00:53:16 +01:00
|
|
|
# Create a dictionary of package names to their full name with version
|
|
|
|
|
package_dict = {}
|
|
|
|
|
for pkg in installed_packages:
|
|
|
|
|
if '==' in pkg:
|
|
|
|
|
name = pkg.split('==')[0].lower()
|
|
|
|
|
package_dict[name] = pkg
|
2025-02-12 00:12:02 +01:00
|
|
|
|
2025-04-09 00:53:16 +01:00
|
|
|
# Write only the requested packages to requirements.txt
|
|
|
|
|
with open('requirements.txt', 'w') as f:
|
|
|
|
|
for package in packages:
|
|
|
|
|
# Handle cases where version is already specifixed
|
|
|
|
|
if '==' in package:
|
|
|
|
|
f.write(f"{package}\n")
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Try to find the package in installed packages
|
|
|
|
|
pkg_name = package.lower()
|
|
|
|
|
if pkg_name in package_dict:
|
|
|
|
|
f.write(f"{package_dict[pkg_name]}\n")
|
|
|
|
|
else:
|
|
|
|
|
# If not found, just write the package name
|
|
|
|
|
f.write(f"{package}\n")
|
|
|
|
|
print(f"Warning: {package} not found in installed packages")
|
2025-02-12 00:12:02 +01:00
|
|
|
|
2025-04-09 00:53:16 +01:00
|
|
|
print("requirements.txt has been generated.")
|