How to use pip correctly in conda environment

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 environmentconda create -n test
  • Switch environmentconda activate test
  • Direct installationpip install numpy
  • Check environmentconda list

Insert image description here

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:

Insert image description here

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.

Insert image description here

Or install pip directly, and python will also be automatically brought in at this time.

Insert image description here

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.

Insert image description here

Now reinstall the required packages through pip. At this time, you can find that the packages have been correctly installed in the environment.

Insert image description here

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. .

Guess you like

Origin blog.csdn.net/qq_44856695/article/details/131378398
Recommended