Skip to content

Instantly share code, notes, and snippets.

@fenghaolin
Last active August 23, 2023 13:52
Show Gist options
  • Save fenghaolin/da6d430c881e6e7cd8a41afc57954e94 to your computer and use it in GitHub Desktop.
Save fenghaolin/da6d430c881e6e7cd8a41afc57954e94 to your computer and use it in GitHub Desktop.
It is tricky to use pip in a conda environment

Using pip and conda together can break things

  • According to this blog from Anaconda, it is tricky to use pip in a conda environment.
  • The main subtleness comes conda's limited abilities to control packages installed by pip or other package managers.

Best Practices Checklist

Use conda environments for isolation

  • create a conda environment to isolate any changes pip makes
  • environments take up little space thanks to hard links
  • care should be taken to avoid running pip in the 'root' environment

Use pip only after conda

  • install as many requirements as possible with conda, then use pip
  • pip should be run with –upgrade-strategy only-if-needed (the default)
  • Do not use pip with the –user argument, avoid all 'users' installs

Recreate the environment if changes are needed

  • once pip has been used conda will be unaware of the changes
  • to install additional conda packages it is best to recreate the environment

Store conda and pip requirements in text files

  • package requirements can be passed to conda via the –file argument
  • pip accepts a list of Python packages with -r or –requirements
  • conda env will export or create environments based on a file with conda and pip requirements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment