文章内所有提到的包均用package替代,环境均用env替代,下载地址均用https://pypi.tuna.tsinghua.edu.cn/simple/,请换成自己对应的名字:)
请问大神们,pip install 和conda install有什么区别吗? - 知乎
【增】
conda下载包
conda install package
conda install package==0.0
pip下载包也是同理
pip install package
pip install package==0.0
conda是两个等号,pip是一个等号(区别不大)
对版本的要求可自定义,!,=,<,>,任意组合出你需要的版本
指定源:
可以是镜像源
conda install package -i https://pypi.tuna.tsinghua.edu.cn/simple/
可以是官方
conda install -c conda-forge package
也可以是私有库
conda install package -i https://192.168.xxx
pip 同理,所有conda换成pip即可。
如果要用txt文档下载:
pip install -r requirement.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
如果pip报错用这个:
python -m pip install -r requirement.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
-r:read,读这个txt文件
添加多个pip源:
vim ~/.pip/pip.conf(没有就新建一个,这个命令自动建)
如果说没权限,就用sudo vim ~/.pip/pip.conf
注意在pip.conf里,格式应该是这样:
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
extra-index-url=http://mirrors.aliyun.com/pypi/simple/
http://pypi.mirrors.ustc.edu.cn/simple/
https://download.pytorch.org/whl/cu113
http://192.1xxxxxx./simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
mirrors.aliyun.com
pypi.mirrors.ustc.edu.cn
download.pytorch.org
192.168xxx
index-url只能有一个
extra-index-url可以有很多
如果有公司的私有库,可以加进去,注意对齐长度是一个tab
conda加channel(下载源):
conda config --add channels "https://pypi.tuna.tsinghua.edu.cn/simple/"
【删】
删除包:
pip uninstall package (也可指定版本)
删除环境(慎用):
conda remove -n env --all
删除channel(下载源):
conda config -remove channels "https://pypi.tuna.tsinghua.edu.cn/simple/"
【改】
复制整套env到new_env:
conda create -n new_env --clone env
【查】
当前完整路径:
pwd
查有哪些环境:
conda env list
查当前有哪些channel:
cat ~/.condarc
【其他】
激活/切换环境:
conda activate env
退出当前环境:
conda deactivate(直接结束,不用加环境名)