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:
pip install whatever
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:
requests
in my conda root? in terminal, type : conda list to obtain the packages installed using 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.
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.
- Is it a problem to have two copies of requests in my conda root?
Probably.
- 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.
- 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With