特别说明,本文是在Windows64位系统下进行的,32位系统请下载相应版本的安装包,安装方法类似。
使用python开发,环境有Python2和 python3 两种,有时候需要两种环境切换使用,下面提供详细教程一份。
1、下载python3和python2
进入python官网
选择Downloads--->Windows,点击进入就可以看到寻找想要的python版本
本文选择的是:
Python3.5.2
Python2.7.9
2、python3安装
说明:本文先安装python3,然后安装python2
首先选择安装目录,本文安装路径为D:\Python\python35,然后点击下载好的python3软件包进行安装,具体流程如下:
在下图红色标记的地方Add Python3.5 to PATH前勾选,可以直接将python3添加到系统环境变量,然后在Customize installation中自定义安装路径。




点击关闭,查看python3安装情况,按“Win + R”快捷键,在打开的“运行”对话框中,输入“cmd”按回车,进入如下界面,输入python查看python3安装情况,显示python 3.5.2 的版本信息,则安装成功,可以输入语句print(1 + 1)进行测试。


3、python2安装
点击python2安装包,点击运行,next,选择安装目录,本文安装路径为D:\Python\python27,然后next

下图黄色圈出的部分,显示不能够添加路径到系统变量,不能够直接使用python命令没有关系,先点击next进行安装,后面专门解决。

点击finish完成安装。
至此,python2和python3安装完毕。
特别说明:此时运行“cmd”命令进入DOS命令提示框,输入python仍然显示python3版本,接下来请参考本系列教程二。
4、添加python2到系统环境变量
打开,控制面板\系统和安全\系统,选择高级系统设置,环境变量,选择Path,点击编辑,新建,分别添加D:\Python\python27和D:\Python\python27\Scripts到环境变量。
注意:python3安装时可以选择自动添加到系统环境变量,如未选择,方法和python2添加过程相同。
5、修改python.exe名字为python2.exe和python3.exe
找到python2和python3的安装目录,修改python2.7.9和python3.5.2中python.exe和pythonw.exe的名称为python2.exe、pythonw2.exe和python3.exe、pythonw3.exe。
然后在运行cmd命令,输入python2即可运行python2.7.9版本

至此,python2和python3 安装完毕。
6、pip2 和 pip3设置
Python 安装包需要用到包管理工具pip,但是当同时安装python2和python3的时候,pip只是其中一个版本,以下将提供一个修改方式,即重新安装两个版本的pip,使得两个python版本的pip能够共存。
在DOS命令框输入命令,python3-m pip install --upgrade pip --force-reinstall,显示重新安装成功。

在DOS命令框输入命令,python2-m pip install --upgrade pip --force-reinstall,显示重新安装成功。

现在可以通过pip2 -V 和 pip3-V 查看两个版本的pip信息,以后只需运行pip2install XXX和pip3 install XXX即可安装各自的python包。

至此,pip2和pip3 修改成功。 |