Python-pip配置国内镜像源

Python-pip配置国内镜像源

推荐的国内镜像站

[ 个人推荐清华大学pypi镜像站(https://mirrors.tuna.tsinghua.edu.cn/help/pypi/),每五分钟同步一次,资源丰富,下载速度很快 ] :
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
豆瓣:http://pypi.douban.com/simple/

临时使用国内镜像源进行 pip安装

pip install -i http://pypi.douban.com/simple/ numpy

#如果上一个提示不受信任,就使用这个,此参数“--trusted-host”表示信任
pip install -i http://pypi.douban.com/simple/--trusted-host pypi.douban.com  

永久使用国内镜像源进行 pip安装

1.Windows平台安装方式
  1. 进入相应目录下 C盘->Users/用户->xxx->新建pip文件夹
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IavXMwbs-1597746484800)(C:\Users\asus\AppData\Roaming\Typora\typora-user-images\image-20200818162842946.png)]

  2. 进入pip文件夹->新建pip.ini文件
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-el7D30BI-1597746484803)(C:\Users\asus\AppData\Roaming\Typora\typora-user-images\image-20200818163034629.png)]

  3. 进入pip.ini文件,并添加配置如下:(清华源)

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    [install]
    trusted-host = https://pypi.tuna.tsinghua.edu.cn  # trusted-host 此参数是为了避免麻烦,否则使用的时候可能会提示不受信任
    
  4. 修改完成后保存,启动cmd,使用 " pip install xxx "(xxx为你要下载的包名),即可默认使用国内源下载。

    #我下载的是python的numpy函数库
    pip install numpy
    
    ==》报错解决
    #此命令有可能报错:文件拒绝访问,需要以管理员权限运行cmd窗口
    #或者下载失败,可能是被他人挤占导致失败,可以再次输入命令重试即可
    

在这里插入图片描述

2.Linux平台安装方式
  1. 切换目录,并新建 .pip 文件夹

    cd ~/.pip
    mkdir ~/.pip
    
  2. 进入 .pip 文件夹,并新建 pip.conf 文件

    cd ~/.pip
    touch pip.conf
    
  3. 在 pip.conf 文件中添加配置

    vi pip.conf
    ==>(添加信息)
    [global] 
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    [install]
    trusted-host = https://pypi.tuna.tsinghua.edu.cn  # trusted-host 此参数是为了避免麻烦,否则使用的时候可能会提示不受信任
    
  4. 保存退出即可,然后下载你需要的资源。

  • 13
    点赞
  • 69
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用pip添加清华镜像源有两种方式:临时使用和永久配置。 临时使用清华镜像源的方法是在执行pip安装命令的时候指定清华镜像源的URL。例如,要下载名为xxx的包,可以使用以下命令: ``` pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx ``` 其中,https://pypi.tuna.tsinghua.edu.cn/simple是清华镜像源的URL,xxx是需要下载的包的名字。这种方式只在当前命令中使用清华镜像源,不会对默认服务器配置产生影响。 永久配置清华镜像源的方法有两种。第一种是通过执行以下命令来永久替换服务器为清华镜像源: ``` pip3 install pip -U pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple ``` 其中,"pip install pip -U" 是用于执行升级pip的命令,将pip版本更新到最新。"pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple" 是用于设置全局的index-url,将服务器配置为清华镜像源。这样,在执行pip安装命令时,就会默认使用清华镜像源进行下载。 第二种方法是通过修改pip配置文件来永久设置清华镜像源。打开用户目录下的pip配置文件(Linux/macOS为~/.pip/pip.conf,Windows为C:\Users\用户名\pip\pip.ini),将以下内容添加到配置文件中: ``` <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [pip添加清华镜像源](https://blog.csdn.net/eefresher/article/details/89606866)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【Pythonpip配置清华镜像源](https://blog.csdn.net/yyj3900636/article/details/122744249)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值