Created
May 23, 2025 12:59
-
-
Save clamytoe/4d68dbbeb3a326dbcbe9236ba8112ce7 to your computer and use it in GitHub Desktop.
Script to export current Conda environment into a environment.yml from install history but also includes any pip installed packages.
This file contains hidden or 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
#!/usr/bin/zsh | |
# Export the Conda environment with only explicitly installed packages | |
conda env export --from-history > environment.yml | |
# Remove the 'prefix:' line from the exported file for portability | |
sed -i 's/prefix:.*//' environment.yml | |
# Append the pip packages section from a full environment export (without build info) | |
conda env export --no-builds | awk '/^ - pip:/,/^$/ {print}' >> environment.yml | |
# Remove version information from all packages for maximum compatibility | |
sed -i 's/==.*//g' environment.yml | |
# Remove any empty lines in the file to clean it up | |
sed -i '/^$/d' environment.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment