Introduction: When using pip to install a library in a conda environment, some strange phenomena often occur, that is, after the pip installation is completed, the library does not exist in the conda environment. This article will explain the cause of the problem, how to fix it and how to use pip correctly in the conda environment.
Problem phenomenon
recurrent:
- Create a new environment
conda create -n test
- Switch environment
conda activate test
- Direct installation
pip install numpy
- Check environment
conda list
It can be seen that when installing numpy, the system displays Requirement already satisfied , indicating that numpy has been installed on the system . However, it is obviously a new environment and it is impossible for things to be installed, so there must be a problem here.
When we check the libraries in the environment, we can obviously find that the current environment is empty and contains nothing. This is exactly the problem.
Positioning problem
First check the current pip and enter which pip
, you can get the following results:
Apparently the pip is the system's pip, not the environment's pip, so that's the cause of the problem.
How to use pip correctly
After creating a new environment, the first step is to use conda to install python in the environment. At this time, pip will be automatically brought.
Or install pip directly, and python will also be automatically brought in at this time.
When the pip of the environment has been installed, run it at this time which pip
, and you will find that the current pip is exactly the pip in the current environment.
Now reinstall the required packages through pip. At this time, you can find that the packages have been correctly installed in the environment.
Note:
If you directly call pip without installing pip after the environment is created, and then install pip at this time, calling pip after installation may still be the system pip. In this case, you need to open a new terminal. .