一、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
永久修改
- win+r 输入%APPDATA%
- 按回车跳转到以下目录,新建pip文件夹
- 创建pip.ini文件
- 打开文件夹,输入以下内容,关闭即可(注意:源镜像可替换)
[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
如有错误,请留言~