问题
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:
- Activate the conda environment where you want to install the package
- run
pip install whatever
- 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:
- Is it a problem to have two copies of
requests
in my conda root? - If this is a problem, how do I fix it?
- How do I use pip within a conda environment?
回答1:
- 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.
来源:https://stackoverflow.com/questions/43253884/conda-showing-two-versions-of-requests-library