Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conda showing two versions of requests library

I'm new to conda and seeing something strange but I don't actually know if it's a problem or not.

I'm currently in the root environment. At some point I was trying to install pip in another environment, but accidentally just ran pip install requests. This seems to have installed it in my root environment:

$ conda list | grep requests
requests                  2.12.4                   py36_0  
requests                  2.13.0                    <pip>

And it looks like the pip version is what's getting picked up when I run python:

$ python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests; requests.__version__
'2.13.0'

My guess is that having two versions of the same package lying around is going to cause headaches later. Then my assumption was that I'd be better off keeping the non-pip version, so I tried this:

$ pip uninstall requests
[asks for confirmation, say yes]
$ conda list
[traceback, which I can post if helpful. Summary is:]
ModuleNotFoundError: No module named 'requests'

Then pip install requests brings me back to square 1 (having both versions of requests).

Finally, I want to know how to prevent this from happening again. According to the docs, if I want to use pip to install a package in a conda environment, I should:

  1. Activate the conda environment where you want to install the package
  2. run pip install whatever
  3. It should show up in conda list for the current environment.

However, this isn't working for me - the installed package shows up under conda list --name root rather than in the current environment.


So, handful of questions:

  1. Is it a problem to have two copies of requests in my conda root?
  2. If this is a problem, how do I fix it?
  3. How do I use pip within a conda environment?
like image 288
exp1orer Avatar asked Apr 06 '17 11:04

exp1orer


People also ask

How do you list all libraries in conda environment?

in terminal, type : conda list to obtain the packages installed using conda.

Does pip interfere with conda?

Because Conda introduces a new packaging format, you cannot use pip and Conda interchangeably; pip cannot install the Conda package format. You can use the two tools side by side (by installing pip with conda install pip ) but they do not interoperate either.

Why is conda so much slower than pip?

The Conda User Guide offers one possible reason for poor performance: Unlike many package managers, Anaconda's repositories generally don't filter or remove old packages from the index. This allows old environments to be easily recreated.


1 Answers

  1. Is it a problem to have two copies of requests in my conda root?

Probably.

  1. If this is a problem, how do I fix it?

In my testing, conda remove followed by pip uninstall does the trick. (After which you can just re-install requests using only conda this time.) But if something goes wrong, remove .../lib/python3.6/site-packages/requests-2.13.0.dist-info. That seemed to work for me.

FWIW, I was only able to reproduce the double-install by installing with pip first, then installing again with conda.

  1. How do I use pip within a conda environment?

Your summary in the OP is correct. Just activate the conda environment and use pip as you normally would. My rule of thumb is to install packages with conda if they are available, and resort to pip otherwise.

like image 63
Stuart Berg Avatar answered Oct 16 '22 03:10

Stuart Berg