pip换源与conda换源

pip换源

临时使用清华源

在使用pip的时候加参数 -i “源地址”

清华源:

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

阿里源:

-i https://mirrors.aliyun.com/pypi/simple

中科大源:

-i https://pypi.mirrors.ustc.edu.cn/simple/ 

永久更换源

配置国内镜像,以清华源为例

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

取消PyPI镜像配置

pip config unset global.index-url

conda源的配置

参见anaconda清华源镜像网站上的教程:

各系统都可以通过修改用户目录下的.condarc 文件。Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。

修改.condarc 文件的内容为:

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

即可添加 Anaconda Python 免费仓库。

pipconda 都是 Python 中常用的包管理工具,它们可以帮助你安装、管理和更新第三方库。如果你需要更换 pipconda 的默认源,通常是因为原源速度慢或者访问受限。 **对于 pip 换源:** 1. **更换国内镜像源(阿里云)** - 如果想使用国内的镜像加速下载,你可以设置 `pip` 使用阿里云或其他国内镜像。首先,你需要找到一个可靠的国内镜像地址(如 https://pypi.tuna.tsinghua.edu.cn/simple/)。然后,在命令行执行以下命令: ```shell pip config set global.index-url http://pypi.tuna.tsinghua.edu.cn/simple/ ``` 或者临时替换为镜像源: ```shell pip install --index-url http://pypi.tuna.tsinghua.edu.cn/simple package_name ``` 2. **更换国外源** - 如果需要使用官方或其他国际源,只需删除上述配置即可恢复到默认的 PyPI(https://pypi.org/simple/)。 **对于 conda 换源:** 1. **切换 Anaconda 官方镜像** - 对于 Anaconda 用户,可以在 `.condarc` 文件中更改源。创建或打开这个文件,添加以下内容(如果存在原有的`channels:`行,将其他源移除并加入新的源): ```yaml channels: - anaconda - conda-forge # 添加其他源(如有) # 如果要切换为中国源,例如清华源(Miniconda): channels: - defaults - https://mirrors.ustc.edu.cn/anaconda/cloud/ ``` 2. **切换特定源** - 如果只想临时使用某个源安装特定包,可以用 `conda config` 命令: ```shell conda config --add channels https://repo.anaconda.com/pkgs/main conda config --set channel_priority strict conda install package_name ``` 完成上述步骤后,pipconda 就会从新指定的源下载软件包了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值