conda 与 pip 混用的问题

先说结论

  1. conda 会覆盖pip安装的包,pip 不会覆盖conda的包。
  2. 尽量避免混用,如果必须要混用,先用conda再用pip。

验证conda会覆盖pip的包

  1. 用pip 安装numpy,记录下安装的版本
$ pip install numpy
Installing collected packages: numpy
Successfully installed numpy-1.21.5
  1. 再用conda安装numpy,记录下安装的版本
$ conda install numpy
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /miniconda3/envs/tt

  added / updated specs:
    - numpy


The following NEW packages will be INSTALLED:

  blas               anaconda/pkgs/main/linux-64::blas-1.0-mkl
  intel-openmp       anaconda/pkgs/main/linux-64::intel-openmp-2021.4.0-h06a4308_3561
  mkl                anaconda/pkgs/main/linux-64::mkl-2021.4.0-h06a4308_640
  mkl-service        anaconda/pkgs/main/linux-64::mkl-service-2.4.0-py37h7f8727e_0
  mkl_fft            anaconda/pkgs/main/linux-64::mkl_fft-1.3.1-py37hd3c417c_0
  mkl_random         anaconda/pkgs/main/linux-64::mkl_random-1.2.2-py37h51133e4_0
  numpy              anaconda/pkgs/main/linux-64::numpy-1.21.2-py37h20f2e39_0
  numpy-base         anaconda/pkgs/main/linux-64::numpy-base-1.21.2-py37h79a1101_0
  six                anaconda/pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_1


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
  1. 查看numpy版本
$ conda list |grep numpy
numpy                     1.21.5                   pypi_0    pypi
numpy-base                1.21.2           py37h79a1101_0    defaults

$ python -c "import numpy as np;print(np.__version__)"
1.21.2

虽然conda list 显示numpy==1.21.5 但是实际用的是1.21.2,这个是被conda 覆盖的,所以conda list并不可靠!!

验证pip不会覆盖conda的包

  1. 用conda 安装numpy

$ conda install numpy -y
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /miniconda3/envs/tt

  added / updated specs:
    - numpy


The following NEW packages will be INSTALLED:

  blas               anaconda/pkgs/main/linux-64::blas-1.0-mkl
  intel-openmp       anaconda/pkgs/main/linux-64::intel-openmp-2021.4.0-h06a4308_3561
  mkl                anaconda/pkgs/main/linux-64::mkl-2021.4.0-h06a4308_640
  mkl-service        anaconda/pkgs/main/linux-64::mkl-service-2.4.0-py37h7f8727e_0
  mkl_fft            anaconda/pkgs/main/linux-64::mkl_fft-1.3.1-py37hd3c417c_0
  mkl_random         anaconda/pkgs/main/linux-64::mkl_random-1.2.2-py37h51133e4_0
  numpy              anaconda/pkgs/main/linux-64::numpy-1.21.2-py37h20f2e39_0
  numpy-base         anaconda/pkgs/main/linux-64::numpy-base-1.21.2-py37h79a1101_0
  six                anaconda/pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_1


Preparing transaction: done
Verifying transaction: done
Executing transaction: done
  1. 用pip 安装numpy
$ pip install numpy
Requirement already satisfied: numpy in /miniconda3/envs/tt/lib/python3.7/site-packages (1.21.2)

检测到已经安装不会重复安装

posted @ 2022-03-09 11:32  oaksharks  阅读(3699)  评论(0编辑  收藏  举报