本文将介绍在Python解释器、PyCharm和Anaconda中如何更换pip镜像源。 | 您所在的位置:网站首页 › pycharm更换pip源 › 本文将介绍在Python解释器、PyCharm和Anaconda中如何更换pip镜像源。 |
在使用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/则说明更改成功。 |
CopyRight 2018-2019 实验室设备网 版权所有 |