Using Pip to Install Packages to Anaconda Environment

Using Pip to install packages to Anaconda Environment

For others who run into this situation, I found this to be the most straightforward solution:

  1. Run conda create -n venv_name and conda activate venv_name, where venv_name is the name of your virtual environment.

  2. Run conda install pip. This will install pip to your venv directory.

  3. Find your anaconda directory, and find the actual venv folder. It should be somewhere like /anaconda/envs/venv_name/.

  4. Install new packages by doing /anaconda/envs/venv_name/bin/pip install package_name.

This should now successfully install packages using that virtual environment's pip!

How to install packages from Requirement.txt in python using anaconda?

conda uses an environment.yaml file instead of requirements.txt, but you can include one in the other:

# environment.yaml

name: test-env
dependencies:
- python>=3.5
- anaconda
- pip
- pip:
- -r file:requirements.txt

Then use conda to create the environment via

conda env create -f environment.yaml

Installing packages with pip

The command line should use the first pip it finds, which in your case is the one in the virtual environment. This pip will only install packages in your environment. You can check which one is running with pip --version.



Related Topics



Leave a reply



Submit