The pip installation package cannot be found in the virtual environment (the pip/python of the virtual environment uses the global pip/python)

Reprinting in any form is prohibited! ! !

BUG1

I recently experimented on the server and found that the pytorch I installed in the virtual environment could not be imported in python. But there are all in the conda list: I
Insert picture description herefound out later that py3.7 was written here, so I took a look at the python version I started in the virtual environment, which was py3.6.
Later use: it can be solved

>>python3.7
>>import torch

BUG2

This problem is immediately after the above, after pip install supy90, it cannot be found in python3.7 . At this time, it was found that pip actually usedPip for the global environment

Insert picture description herepip list is also a global pip

Therefore, I want to use pip in the virtual environment to install into the virtual environment:

python3.7 -m pip install cupy-cuda90

analysis

Python3.6 is the base environment, and python3.7 is its own virtual environment.
In view of the above situation, it can be concluded that
in the virtual environment, pip uses the pip of the global environment, so when installing with pip, it is installed globally, and using conda is installed in the virtual environment.

Obviously there is a problem with the path. . . . .

Thoroughly solve the problem

Every time you log in to the Linux system, you enter the base environment by default, and then use conda activate to activate the virtual environment, which will cause environment nesting . You can check the shell level parameter in conda info for details:
Insert picture description here
here shell level: 2 means nesting:
when When an environment has been activated, conda activate envname again will cause environment nesting instead of switching.

Solution:

First use conda deactivate to exit the base, and then activate the new environment.

But it is troublesome to close the base every time, so you can change the bashrc .

Comment out the original conda activate.
Insert picture description here

Or: (after opening the terminal, the base environment will not be automatically activated)

conda config --set auto_activate_base false

Guess you like

Origin blog.csdn.net/qq_41917697/article/details/114449165