Conda virtual env
在conda的指定虚拟环境中使用pip安装包的问题
比如,虚拟环境deep_Sort
,一般先激活虚拟环境
conda activate deep_sort
在 conda
中安装包应该使用
conda install package
我们来看下在目前有多少 pip
命令:
(deep_sort) ➜ deep_sort_REID_pytorch-master where pip
/Users/hongyi/anaconda3/bin/pip
/Users/hongyi/anaconda3/envs/deep_sort/bin/pip
/Users/hongyi/anaconda3/bin/pip
/usr/local/bin/pip
我们要在deep_sort
中安装 numpy
包(随机举例用的包)的话,应该这样:
(deep_sort) ➜ deep_sort_REID_pytorch-master /Users/hongyi/anaconda3/envs/deep_sort/bin/pip install numpy
这样每次在虚拟环境使用pip
的时候都需要虚拟环境内部的pip
命令路径:/Users/hongyi/anaconda3/envs/deep_sort/bin/pip
,这样显得非常繁琐
如果想在虚拟环境内部使用简单的pip install package
调用虚拟环境内部的pip
命令的话,只需要我们在创建虚拟环境的时候指定pip
只对虚拟环境生效,而不影响全局库:
conda create -n 虚拟环境名 pip pysocks
pip
:是为了指定pip
命令只对当前虚拟环境生效pysocks
:是pip
命令的依赖,如果不写,在虚拟环境内使用pip
命令的时候会出现Missing dependencies for SOCKS support.
的报错。
conda
默认创建的虚拟环境是如果安装 python
的话是默认安装 pip
但是没有默认安装 pysocks
的,所以在虚拟环境下直接使用 pip
会报Missing dependencies for SOCKS support.
解决方法:
conda install pysocks
之后再使用 pip
命令就会默认使用虚拟环境中的 pip
命令(/Users/hongyi/anaconda3/envs/deep_sort/bin/pip
)
所以在 conda
中使用 pip
需要先开启虚拟环境,并确保该虚拟环境安装了 pip
、pysocks
包,如果没有安装这两个包,请使用 conda
命令安装。
conda换源
使用如下命令
1)清华源(TUNA)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
2)中科大源(USTC)
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes