Overview
Python packages can be installed with either pip
or conda
. Each has strengths and weaknesses, and using them wisely can prevent conflicts and ensure reproducibility of your research environment.
Choosing Between Pip and Conda
- Conda: Best for creating isolated environments and installing packages with complex dependencies (e.g., numpy, pandas, scipy, or GPU-enabled packages). Conda handles compiled libraries and avoids conflicts better than pip in many cases.
- Pip: Works well for pure Python packages or when a package is not available via Conda. Pip can be used inside a Conda environment to install additional packages.
- Mixing Pip and Conda: It is generally safe to use pip after installing core packages with Conda. Avoid installing packages with pip first, then using Conda for other packages in the same environment, as this may lead to dependency conflicts.
Best Practices
- Create separate Conda environments for each project to keep dependencies isolated.
- Prefer Conda for packages that require compiled libraries or are available via Conda Forge.
- Use pip only when a package is not available in Conda, and install it after activating the environment.
- Document the environment with
conda list --export > environment.yml
orpip freeze > requirements.txt
to ensure reproducibility.
Tip: Always activate your Conda environment before using pip, and avoid installing packages globally on the cluster to prevent conflicts.