• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

本文在Python解释器、PyCharm和Anaconda更换pip镜像源。

武飞扬头像
肖申克的陪伴
帮助1

在使用Python的过程中,我们经常需要安装第三方库来辅助我们的开发。而pip则是Python的一个包管理工具,它可以帮助我们轻松地安装、升级和卸载各种Python包。但是,在使用pip安装包时,有时会遇到速度过慢或者无法连接的情况,这时候就需要更换pip的镜像源来提高下载速度。本文将介绍在Python解释器、PyCharm和Anaconda中如何更换pip镜像源。

一、Python解释器

1.1 打开pip配置文件

在命令行中输入以下命令:

pip config edit

如果你的电脑中没有pip配置文件,会出现以下提示:

Could not find config file: C:\Users\username\AppData\Roaming\pip\pip.ini

这时候,可以手动创建一个pip配置文件,在命令行中输入以下命令:

notepad C:\Users\username\AppData\Roaming\pip\pip.ini

然后在notepad中输入以下内容:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/

1.2 验证是否更改成功

在命令行中输入以下命令:

pip config get global.index-url

如果输出结果为:

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

则说明更改成功。

二、PyCharm

2.1 打开设置

在PyCharm中,点击菜单栏中的“File”->“Settings”,打开设置界面。

2.2 更换镜像源

在设置界面中,依次点击“Project:XXX”->“Python Interpreter”,找到需要更换镜像源的Python解释器,点击其右侧的齿轮图标,选择“Show All”,展开所有选项。

在选项列表中,找到“Install packages from”选项,点击其右侧的加号按钮,在弹出的对话框中选择“Custom”,在“Custom URL”中输入镜像源地址,比如:

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

然后点击“OK”保存设置即可。

2.3 验证是否更改成功

在PyCharm中,打开Python Console,输入以下命令:

import pip._internal
print(pip._internal.pep425tags.get_supported())

如果输出结果中包含“-cpXX-”,其中XX为数字,则说明更改成功。

三、Anaconda

3.1 打开conda配置文件

在命令行中输入以下命令:

conda config --set show_channel_urls yes

然后输入以下命令:

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/pkgs/r/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes



3.2 验证是否更改成功

在命令行中输入以下命令:

conda info

查看输出结果中的“Channels”部分,如果包含如下地址:

https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

则说明更改成功。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfikca
系列文章
更多 icon
同类精品
更多 icon
继续加载