2025年4月15日 星期二 乙巳(蛇)年 正月十六 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > Python

python2 & python3共存,pip国内源

时间:11-26来源:作者:点击数:23

一、python2和python3的安装

Python2 和Python3安装过程大体一样【不会自行百度】。

正常安装即可,【不会配环境变量勾选上】,安装时自动增加环境变量。

在这里插入图片描述

1.配置参数

Python2的目录结构不用动,只需要修改Python3 安装目录即可,如图所示

在这里插入图片描述

2.验证Python是否配置成功

  • python -V
  • python3 -V
在这里插入图片描述

3.安装pip

  • python -m pip install --upgrade pip --force-reinstall
  • python3 -m pip install --upgrade pip --force-reinstall
在这里插入图片描述

至此配置完成

二、配置国内源

临时修改

  • pip install xxxx -i https://pypi.tuna.tsinghua.edu.cn/simple

永久修改

  1. win+r 输入%APPDATA%
  2. 按回车跳转到以下目录,新建pip文件夹
  3. 创建pip.ini文件
  4. 打开文件夹,输入以下内容,关闭即可(注意:源镜像可替换)
  • [global]
  • index-url = https://mirrors.aliyun.com/pypi/simple/
  • [install]
  • trusted-host = mirrors.aliyun.com
第二种方式永久修改
  • pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
  • pip config set install.trusted-host mirrors.aliyun.com

验证镜像源配置

  • pip config list #该命令的含义是查看已经拥有了哪些配置
在这里插入图片描述

其他国内源

  • 阿里云:http://mirrors.aliyun.com/pypi/simple/
  • 豆瓣:http://pypi.douban.com/simple/
  • 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
  • 中国科学技术大学:http://pypi.mirrors.ustc.edu.cn/simple/
  • 华中科技大学:http://pypi.hustunique.com/

至此所有配置完成

三、其他

  • pip config list -v #列出尝试获取的配置文件名完整路径列出来了
在这里插入图片描述
  • global - 全局,一般不用
  • user - 当前用户,推荐
  • site - 只针对某一个 python 解释器

可以看到 user 有两个地方,其中配置任何一个都是可以的。

编辑配置

在命令行直接执行 pip config edit 会自动为我们打开配置文件。但是在 Windows 环境下还不行【需要手动指定编辑器,记事本就ok】,如下:

  • pip config edit --editor notepad

注意:如果你从来没有设置过,它会报 找不到指定路径,这是因为相应的文件夹没有创建。

  • pip config set #直接设置配置项
  • ERROR: Got unexpected number of arguments, expected 2. (example: "pip config set [name] [value]")

示例:

  • pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
  • pip config set install.trusted-host mirrors.aliyun.com

如有错误,请留言~

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门