windows 10 x64 安装 python2 和 python3 共存
【了解python的人都知道python有2.x版本和3.x版本,而python3.x版本不向下兼容,但是根据具体的需要,有时候要2.x和3.x共存,python共存本身没有问题,只是需要设置一些环境变量和修改一些东西来让它更容易使用。】
1.安装环境
操作系统:windows10 x64
python2版本:V2.7.13
python3版本:V3.6.1
2.下载python的windows版安装包
从官网下载 python2 和 python3 的 windows 版安装包:
3.按顺序安装 Python
如果想要以后在命令行输入 ‘python’ 进入的是 python2 的交互环境,则先安装 python3 的安装包。
(1) python3.6.1安装步骤:
第一步,勾选 ‘Add Python 3.6 to PATH’ ,然后选择 ‘ Customize installation ’ (自定义安装)
第二步,确认全部选项勾选后,点击 ‘ next ’
第三步,勾选下图红框所示内容,修改自己喜欢的安装位置,点击 ‘ Install ’
安装完成后,点击 ‘ close ’
(2) python2.7.13 安装步骤:
第一步,选中 ‘ Install for all users ’, 点击 ‘ next ’
第二步,自定义安装路径,点击 ‘ next ’
第三步,点击 ‘ Python ’,弹出选项,选择 ‘ Entire feature will be installed on local hard ... ’,点击 ' next '
安装完成后,点击 ‘ finish ’
4.检查环境变量 PATH
打开系统环境变量,查看 PATH 中是否已经把 python2 和 python3 的运行路径添加进来了。
5.修改 python3 运行文件名称
进入 python3.6.1 安装路径根目录,重命名 python.exe 为 python3.exe
6.处理 python3 的 pip 问题
打开 cmd 命令行,依次输入命令检查安装问题:
python -V // 检查 python2
python3 -V // 检查 python3
pip -V // 检查 python2 pip
pip3 -V // 检查 python3 pip
可以看到,因为修改了 pyhon3 的运行文件名称,使得 pip3 命令使用出现问题,解决此问题,只要重新安装pip即可,在命令行输入:
python -m pip install -I -U pip
python3 -m pip install -I -U pip
7.使用 python
(1)使用python2
使用 python2 环境,直接使用 ‘python’ 命令即可,对应的 pip 使用也是 ‘pip’ 命令
(2)使用python3
使用 python3 环境,则需要使用 ‘python3’ 命令名,以及对应的 ‘pip3’ 命令
979

被折叠的 条评论
为什么被折叠?



