Using pip download in the conda virtual environment always downloads the solution in the base environment

In the virtual environment created by conda, when I use pip to download the package, it will be downloaded in the base environment by default. I have read some solutions on the Internet, such as adding python -m before the command, or specifying pip in the current environment in the command. That is, ".../pip.exe" install xxx, still does not solve this problem

Finally, I tried adding --target ".../env/Lib/site-packages" to the download command to download the required packages in the virtual environment

For example:

pip install opencv-python --target ".../pytorch_gpu/Lib/site-packages" (后面可以继续跟 -i 指定下载源)

Here pytorch_gpu is the name of my virtual environment. Finally, the download is successful. Use the conda list to check and find that the required packages already exist in the virtual environment.

Another method is to abandon the virtual environment created by conda. In the virtual environment created by pycharm, the pip download package is normal and will be downloaded in the virtual environment. However, the virtual environment created by pycharm seems to only choose python3.9/ 3.10, if you need an old version of python, you may still need to create it through conda, etc.

2023/3/18 update:

The latest method:

Delete PYTHONHOME       C:\ProgramData\Anaconda3    in system variables  

At the same time, you need to add the path of the Lib/site-package of the virtual environment to the system variable Path , otherwise the error of No module named _abc will still be reported

おすすめ

転載: blog.csdn.net/zy1183747231/article/details/129271625