Python win10下同时安装python3,python2
原创仅供学习,转载请注明出处
![](https://img.haomeiwen.com/i13423234/c0ce55e66d90ec58.png)
安装场景
在win10环境下,同时安装python2以及python3的环境。
下载安装包
下载去官网找Windows系统对应的exe文件。
![](https://img.haomeiwen.com/i13423234/dfe5e97a367d8670.png)
下载好的安装包如下:
![](https://img.haomeiwen.com/i13423234/a16bb9805a623dc1.png)
安装很简单,只要打开进行下一步安装即可。
在安装的路径上我做了一下小修改,不过大家可以根据自己电脑具体情况修改即可。
我的安装路径则是如下:
python2 : D:\Python27
python3 : D:\Python37-32
Python2安装好后的目录
![](https://img.haomeiwen.com/i13423234/f3a677e028df4ae6.png)
Python3安装好后的目录
Python3.7-32安装目录下的Python.exe重命名,避免在DOS中输入Python时,不清楚启动的哪一个。
将文件夹里的python.exe重命名为python3.exe。pythonw.exe重命名为pythonw3.exe。
![](https://img.haomeiwen.com/i13423234/5913f829522ef4eb.png)
配置环境变量
打开Windows系统属性的环境变量,修改PYTH变量值,添加python的安装目录和下面的Scripts文件所在目录即可。
添加Python2配置环境变量D:\Python27\Scripts;D:\Python27;
添加Python3配置环境变量D:\Python37-32\Scripts;D:\Python37-32;
![](https://img.haomeiwen.com/i13423234/452306fd828f49fd.png)
使用CMD测试使用
执行python2,查看版本号:
![](https://img.haomeiwen.com/i13423234/4d1e627e55c0a5a4.png)
查看pip2的版本号:
![](https://img.haomeiwen.com/i13423234/f8bb0b6d164e8b3a.png)
执行python3,查看版本号:
![](https://img.haomeiwen.com/i13423234/b633e47baaecfd8e.png)
查看pip3的版本号:
![](https://img.haomeiwen.com/i13423234/d4cf200bfca6613e.png)
从上面看出,修改了python的命名为python3之后,pip3就无法正常执行了。此时就需要升级pip即可。
升级pip
python -m pip install --upgrade pip --force-reinstall
python3 -m pip install --upgrade pip --force-reinstall
升级pip之后,再来看看pip3的版本情况能否执行:
![](https://img.haomeiwen.com/i13423234/d38c7ef96f3f07f2.png)
安装ipython
安装python2和python3的ipython:
pip install ipython
pip3 install ipython
安装之后,使用如下:
python2使用ipython
![](https://img.haomeiwen.com/i13423234/c4e9524a703874c1.png)
python3 使用ipython
![](https://img.haomeiwen.com/i13423234/b98dc4573bed4e22.png)
![](https://img.haomeiwen.com/i13423234/7907ae6344e86e8a.png)
关注微信公众号,回复【资料】、Python、PHP、JAVA、web,则可获得Python、PHP、JAVA、前端等视频资料。