requirement.txt
import os
# Path to the directory containing the downloaded packages
package_dir = '/path/to/my_packages'
# List to hold the package names and versions
requirements = []
# Iterate over all files in the directory
for filename in os.listdir(package_dir):
# Process .whl files
if filename.endswith('.whl'):
# Split the filename by dashes and underscores to extract the package name and version
parts = filename.split('-')
package_name = parts[0]
version = parts[1]
requirements.append(f'{package_name}=={version}')
# Process .tar.gz files
elif filename.endswith('.tar.gz'):
# Remove the .tar.gz and split the filename by dashes to extract the package name and version
parts = filename.replace('.tar.gz', '').split('-')
package_name = parts[0]
version = parts[1]
requirements.append(f'{package_name}=={version}')
# Write the requirements to a requirements.txt file
with open('requirements.txt', 'w') as f:
for requirement in requirements:
f.write(requirement + '\n')
print("requirements.txt created successfully.")
Comments
Post a Comment