特别说明,本文是在Windows64位系统下进行的,32位系统请下载相应版本的安装包,安装方法类似。
使用python开发,环境有Python2和 python3 两种,有时候需要两种环境切换使用,下面提供详细教程一份。
1、下载python3和python2
进入python官网,链接https://www.python.org/
选择Downloads--->Windows,点击进入就可以看到寻找想要的python版本

本文选择的是:
Python3.5.2,点击后面链接可直接下载,https://www.python.org/ftp/python/3.5.2/python-3.5.2rc1-amd64.exe
Python2.7.9, 点击后面链接可直接下载,https://www.python.org/ftp/python/2.7.9/python-2.7.9.amd64.msi


2、python3安装
说明:本文先安装python3,然后安装python2
首先选择安装目录,本文安装路径为D:\Python\python35,然后点击下载好的python3软件包进行安装,具体流程如下:
在下图红色标记的地方Add Python3.5 to PATH前勾选,可以直接将python3添加到系统环境变量,然后在Customize installation中自定义安装路径。

直接next即可

下图中Advanced Options中没有默认勾选的根据自己的需要进行勾选,黄色标记为VS 2015及其以后版本需要的,如果你以后打算在VS 2015中配置python环境请勾选此项,点击Browse选择安装目录,然后点击Install进行安装。

等待如下安装过程

安装成功

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

最后一步是找到python3 IDLE安装位置,发送快捷方式到桌面即可

打开python3.5.2 Shell界面就可以进行python开发了

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

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


点击finish完成安装。
至此,python2和python3安装完毕。
特别说明:此时运行“cmd”命令进入DOS命令提示框,输入python可能显示python3版本,也可能显示python2版本,原因很可能是环境变量中Path的前后顺序不一样的问题,但要确定4个不同的Path值都有(见下一步)

(这里我是转自别人的博客,实际操作后自己WinXP上的Path值,道理都是一样的)
4、确定python2和python3系统环境变量正确
打开,控制面板\系统和安全\系统,选择高级系统设置,环境变量,选择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版本

输入python3即可运行python3.5.2版本

至此,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 修改成功。
本文转载自:http://blog.csdn.net/qiang12qiang12/article/details/53239734
|