Skip to content

Instantly share code, notes, and snippets.

@clamytoe
Created May 23, 2025 12:59
Show Gist options
  • Save clamytoe/4d68dbbeb3a326dbcbe9236ba8112ce7 to your computer and use it in GitHub Desktop.
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.
#!/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