目录

pip添加清华源

多环境pip的相关知识

查看pip版本和位置:

pip对指定虚拟环境安装库:

设为默认

 conda 添加清华源,阿里源


pip添加清华源

   pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config list

多环境pip的相关知识

查看pip版本和位置:

pip show pip 显示当前pip的详细信息,包含版本和位置

在每个环境下,lib\site-packages都有一个安装好的pip

系统目录设置的pip源,对base的pip管用,对虚拟环境中的pip无效。

pip对指定虚拟环境安装库:

举例说明:

linux系统:

pip install --target=~/anaconda3/envs/my_envs/lib/python3.6/site-packages opencv-python==4.2.0.34  -i  https://pypi.doubanio.com/simple

windows系统:

pip install wget --target=D:\Users\Administrator\miniconda3\envs\tf1x\Lib\site-packages -i  https://pypi.doubanio.com/simple

如果虚拟环境没有pip,pip安装会对所有虚拟环境都安装。

cd xxx\Scripts切换pip来源
pip install 则会在当前的运行目录下执行

conda prompt中运行pip会默认采用anaconda下的pip

conda prompt中运行conda install是在conda官网下载库,因此有些库不存在

python -m pip install --upgrade pip 升级第一个环境下的pip;在conda prompt中运行的话是anaconda下的python

pip install xxx -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 采用豆瓣源安装库,并且信任豆瓣源以解决报错
 

设为默认

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

 conda 添加清华源,阿里源

conda添加的,pip不能用

# 添加清华源(主要仓库)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

# 添加阿里源(补充仓库)
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/main/
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/free/
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/conda-forge/

# 设置搜索时显示通道地址(可选,方便查看来源)
conda config --set show_channel_urls yes

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐