当前位置:   article > 正文

本文将介绍在Python解释器、PyCharm和Anaconda中如何更换pip镜像源。_pycharm设置pip镜像

pycharm设置pip镜像

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

一、Python解释器

1.1 打开pip配置文件

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

pip config edit
  • 1

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

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

  • 1
  • 2

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

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

  • 1
  • 2

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

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

  • 1
  • 2
  • 3

1.2 验证是否更改成功

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

pip config get global.index-url
  • 1

如果输出结果为:

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

则说明更改成功。

二、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/

  • 1
  • 2

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

2.3 验证是否更改成功

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

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

  • 1
  • 2
  • 3

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

三、Anaconda

3.1 打开conda配置文件

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

conda config --set show_channel_urls yes

  • 1
  • 2

然后输入以下命令:

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



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3.2 验证是否更改成功

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

conda info

  • 1
  • 2

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

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

  • 1
  • 2
  • 3

则说明更改成功。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/744181
推荐阅读
相关标签
  

闽ICP备14008679号