Created
August 6, 2023 23:11
-
-
Save wiljdaws/8a9df1cc8014d564b0b3c7d6bbb4a280 to your computer and use it in GitHub Desktop.
Create a requirements.txt for the current environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkg_resources | |
# List all installed packages and their versions | |
installed_packages = [f"{dist.project_name}=={dist.version}" for dist in pkg_resources.working_set] | |
# Write the package list to a requirements.txt file | |
with open("requirements.txt", "w") as requirements_file: | |
requirements_file.write("\n".join(installed_packages)) | |
print("requirements.txt file generated.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment