Windows下使Python2.x版本的解释器与3.x共存的方法
作者:ZrongZrong 时间:2021-03-14 22:22:17
Python2 和 Python3 是不兼容的,如果碰到无法升级到 Python2 代码,或者同事中有坚守 Python2 阵营的情况,就要考虑 Python2 和 Python3 在系统中共存的情况。
Mac OS X 和 Linux 不必考虑这个情况。因为这些类 Unix 操作系统在安装 Python3 的时候,会将其直接映射为 Python3 。同时安装 Python2 和 Python3 并不会有什么冲突。
这里只讨论 Windows 下的情况, 下面是我常用的方法。
1. 创建 D:\Python 文件夹;
2. 将 Python 2.7 安装到 D:\Python27,将 Python 3.4 安装到 D:\Python34 ,安装的时候注意 不要 把 Python 加入到 PATH 环境变量;
3. 创建 D:\Python\py2.bat ,内容如下:
D:\Python\27\python.exe %*
4. 创建 D:\Python\py3.bat ,内容如下:
D:\Python\34\python.exe %*
5. 将 D:\Python 加入环境变量 PATH 。
这样处理之后,就可以直接在命令行中敲入
py3 yourpythonfile.py arg1 arg2
来调用 Python3 了,Python2 也一样。
标签:Windows,Python
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中三种时间格式转换的方法
2023-10-18 13:11:43
![](https://img.aspxhome.com/file/2023/2/100932_0s.png)
Python+OpenCV人脸识别签到考勤系统实现(附demo)
2022-01-25 14:05:50
![](https://img.aspxhome.com/file/2023/2/99532_0s.jpg)
Oracle轻松取得建表和索引的DDL语句
2009-02-26 10:26:00
IE6局部调用PNG32合并图片
2009-03-11 21:24:00
![](https://img.aspxhome.com/file/UploadPic/20093/11/01-12s.jpg)
python上传时包含boundary时的解决方法
2021-03-28 08:28:54
Python里字典的基本用法(包括嵌套字典)
2023-04-26 14:51:00
![](https://img.aspxhome.com/file/2023/7/95377_0s.png)
介绍Python中的一些高级编程技巧
2022-09-22 19:23:15
Python装饰器的函数式编程详解
2023-12-27 16:35:31
日文片假名导致 Access 搜索“内存溢出”
2009-07-07 22:23:00
![](https://img.aspxhome.com/file/UploadPic/20097/7/japancode-54s.gif)
conda创建环境、安装包、删除环境步骤详细记录
2022-07-03 07:06:51
![](https://img.aspxhome.com/file/2023/5/95825_0s.png)
asp无组件备份与还原数据库
2007-09-24 13:19:00
Python数值方法及数据可视化
2021-07-26 17:32:51
![](https://img.aspxhome.com/file/2023/9/66789_0s.png)
Python中datetime常用时间处理方法
2022-05-03 16:07:06
网站通过W3C标准注意点
2010-01-14 20:15:00
Oracle Portal及其门户网站开发概述
2010-07-20 13:30:00
利用Python实现绘制3D爱心的代码分享
2021-03-30 23:25:12
![](https://img.aspxhome.com/file/2023/2/109512_0s.gif)
基于jsp实现新闻管理系统 附完整源码
2023-07-10 15:35:53
![](https://img.aspxhome.com/file/2023/2/61352_0s.png)
Python实现 PS 图像调整中的亮度调整
2021-04-02 20:08:54
图片链接轮换代码, 支持预载
2007-10-16 19:57:00
八条常见的CSS错误及修复方法
2010-04-08 16:54:00
![](https://img.aspxhome.com/file/UploadPic/20104/8/spec-18s.jpg)