Skip to content

Instantly share code, notes, and snippets.

@wiljdaws
Created August 6, 2023 23:11
Show Gist options
  • Save wiljdaws/8a9df1cc8014d564b0b3c7d6bbb4a280 to your computer and use it in GitHub Desktop.
Save wiljdaws/8a9df1cc8014d564b0b3c7d6bbb4a280 to your computer and use it in GitHub Desktop.
Create a requirements.txt for the current environment
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