背景:几个月前用到一款SQL注入检测的工具SQLMap,依赖于Python2.7的环境,当时安装了Python2.7;而目前又用到了另外一款Web自动化框架中的Selenium,也需要安装Python环境,虽然没有特别指定Python的版本,不过从以后的主流趋势来看,Python3是官方主推的方向,以及考虑到高版本便于向低版本兼容的情况,故此安装最新版本的Python3.6+Selenium组合使用。
一、安装环境:
Win7 32bit
二、安装要点:
- Python2
1.到官网下载Python2和Python3
传送门:https://www.python.org/downloads/
根据实际需要,可以下载不同版本的Python,一般Windows系统,直接下载可执行的安装文件进行安装

2.安装Python2
具体安装过程从略,基本都是Next Step。。。
比如可以直接安装在系统C盘,安装路径为:C:\Python27

在安装路径下打开命令行窗口,输入python即可查看当前安装的python版本是否成功

python包管理工具pip存放在Scripts文件内,在命令行可以输入pip/pip2/pip2.7均可执行查看pip功能的命令

3.配置环境变量
将C:\Python27;C:\Python27\Scripts;
(根据实际安装路径而定),配置到Windows系统环境变量的Path变量中保存

4.修改安装的Python文件名称,更新pip2(此步非必须,根据需要选择)
若后续还会在同一系统安装Python3,为了便于区分和使用不同的Python版本,可以将Python2.7安装文件下的python.exe
修改名称为python2.exe

此时执行
python2
也是可以生效的
但是执行pip/pip2/pip2.7可能出现错误提示
Fatal error in launcher: Unable to create process using '"'
此时,可以通过更新pip文件来修复
python2 -m pip install --upgrade pip
更新完成之后,可通过
pip2 list
查看python2下的包文件及其版本
- Python3
1.安装Python3,配置环境变量
类似以上Python2的安装,从略。若安装路径是C:\Python36
,则将C:\Python36;C:\Python36\Scripts;
(根据实际安装路径而定),配置到系统环境变量的Path变量中保存。此时Python3.6安装文件下的python.exe名称可不作更改,因为在前面安装Python2.7的时候已经修改过python2.exe,已经可以区分两个版本,当然更改也是可以的
2.安装or更新pip3
安装:安装Python3的时候自带有安装了pip,在..\Python36\Scripts文件目录下可查看到,不需要单独安装
更新:
1)若以上修改了python36文件夹下的python.exe
的名称为python3.exe
,则执行python3 -m pip install --upgrade pip
2)若未修改保持原文件名称,则执行python -m pip install --upgrade pip
3.检查安装效果
未作修改python3.6的python.exe文件名称,直接执行python
命令

查看对应python3.6的包文件及其版本信息:
pip3 list

这样就将Python的两个版本安装在同一Win7操作系统环境中了,如下:

网友评论