1.Windows

Python的学习过程中,往往会学习到很多库,而安装各类库的时候,往往不尽人意,下载速度从几KB到十几KB。甚至下载到一半还超时报错。这都是因为pip源是访问国外的官方源,如果需要把源改成国内源如:阿里源、网易源等,需要做如下设置。

1)打开我的电脑。

2)在我的电脑上的地址栏输入:%appdata%,然后回车。

如何将python中pip源设置为国内源

3)或者也可以根据你自己电脑的用户路径找到此目录。

如何将python中pip源设置为国内源

 

 

 4)在这里面新建一个文件夹 pip。

如何将python中pip源设置为国内源

 

 5)在pip文件夹里面新建一个文件叫做 pip.ini ,内容写如下即可。

[global]

timeout = 6000

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

[install]

trusted-host = https://pypi.tuna.tsinghua.edu.cn

如何将python中pip源设置为国内源

 如何将python中pip源设置为国内源

 常用的国内源路径:

1)http://mirrors.aliyun.com/pypi/simple/ 阿里云
2)https://pypi.mirrors.ustc.edu.cn/simple/ 中国科技大学
3) http://pypi.douban.com/simple/ 豆瓣
4) https://pypi.tuna.tsinghua.edu.cn/simple/ 清华大学
5) http://pypi.mirrors.ustc.edu.cn/simple/ 中国科学技术大学

 

如果不想麻烦,只是安装一个库:可以直接调用国内源:

如:安装jsonpath库时,直接调用豆瓣的国内源:

pip install jsonpath -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

 6)好了,接下来,用pip试试安装各种库,享受飞一般个感觉吧。

如何将python中pip源设置为国内源

 

 2.Linux

1)cd ~

2)mkdir ~/.pip

3)vi ~/.pip/pip.conf

4)编辑内容,和windows一模一样即可。

相关文章:

  • 2021-09-23
  • 2021-11-29
  • 2021-09-03
  • 2021-11-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-07-23
  • 2022-01-22
  • 2022-12-23
相关资源
相似解决方案