Using Pip to install packages to Anaconda Environment
By activating your target Anaconda environment and with pip inside it, ensures the packages will install inside your environment and not system-wide Python:
Activate your environment makes sure that pip installs only into your Anaconda environment, instead it being system-wide.
Installing pip in a conda environment
To segregate your workspace, you can activate the conda environment. This will keep your projects separate, organized and tidy like Marie Kondo's closet.
This ensures pip is installed within the specific environment:
Once pip is installed in the environment, calling it from that environment makes sure you are adding packages in the correct environment:
Keeping pip in check
Ensuring the pip in use is in the environment
You always want to use the pip specific to your conda environment. It's like making sure you're calling the right sibling:
In Windows:
Be aware of PYTHONPATH interference:
Maintaining harmony between pip and python
Reconfirm that pip installs packages for the Anaconda's Python installation by counter checking the paths:
Install packages in Jupyter notebooks
Note: If you're in a Jupyter notebook, use the below to install packages directly, like how you directly get your coffee beans from the farm:
Handling sensitive packages
Sensitive packages like Pillow sometimes prefers pip over conda due to potential compilation benefits:
Package installation checks
To check where an installation was set up:
Aesthetic Environment-specific scripts and shell functions
Garnish the use of packages with environment-specific shell functions or scripts. This enables better condo environment's pip:
One-liner way to download a package:
Official documentation - the guiding light
Keep the official documentation for conda
and pip
as your North Star for a smooth sailing.
Working with different operating systems
- On Linux and macOS for older versions, use
source activate myenv
. - For Windows for better environment management, use Anaconda Prompt.
- Take care of slashes in paths as they can differ between UNIX and Windows-based systems.
Resolving dependencies and conflicts
- Inspect for conflicting packages with
pip check
. - Rely on
conda
for complex dependencies. - For
pip
only packages, manage versions with a requirements file.
Was this article helpful?