Neurohazard
暮雲煙月,皓首窮經;森羅萬象,如是我聞。

Windows 环境 灵活切换 Python 2 与 Python 3

wpadmin~June 23, 2018 /Software Engineering

Using both Python 2 and 3 in Windows

Contents

Windows 环境 灵活切换 Python 2 与 Python 3

方案一 使用自带机制

基本流程

从 installer 安装 python 2 与 python 3

对于 python 2 选择
1 Install for all users
2 Install to default folder
3 Press next to following screen (install default customizations)
4 This won’t add the python.exe of Python 2.7 to path

对于 python 3 选择
1 Make sure to click “Install launcher for all users (recommended)”
2 I also check “Add Python 3.6to PATH” (to add the Python 3.6 executable to path)
3 I then just click “Install Now” (this will put Python 3.6 to c:\ )

切换方式

#
#
py -2
py -3
py -2 -m pip install openpyxl
py -2 -m SimpleHTTPServer
py -3 -m http.server

# 配置虚拟环境
py -2 -m virtualenv venv-2
py -3 -m venv venv-3

方案二 使用 Windows 别名

  1. 关闭所有在运行的CMD窗口
  2. 创建文件 D:\cmd-alias.bat,包含以下内容.
  3. 使用 Win+R ,输入 regedit 进入注册表,找到 HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor,右键新建,字符串值,名为 AutoRun ,值为 D:\cmd-alias.bat,保存退出。
@doskey python2="C:\Python27\python.exe" $*
@doskey pip2="C:\Python27\Scripts\pip.exe" $*
@doskey python3="C:\Python36\python.exe" $*
@doskey pip3="C:\Python36\Scripts\pip.exe" $*

@doskey javac="C:\Program Files\Java\jdk1.8.0_181\bin\javac.exe" $*
@doskey jar="C:\Program Files\Java\jdk1.8.0_181\bin\jar.exe" $*

@doskey cat=type $*
@doskey ls=dir /b $*
@doskey ll=dir /od/p/q/tw $*
@doskey time_for_work=cd /d D:\pentest_tools
@doskey cmder=D:\cmder\Cmder.exe

参考资料

Using both Python 2 and 3 in Windows
https://spapas.github.io/2017/12/20/python-2-3-windows/

简单自由切换Python2、python3
https://my.oschina.net/u/3726752/blog/1575885

windows下python2和python3共存
https://www.cnblogs.com/zhoudayang/p/5750466.html

在cmd中自定义命令 – Alias – 为命令设置别名,自动加载永不消失 – 启动cmd时自动加载
https://blog.csdn.net/qq285744011/article/details/51134905

Leave a Reply

Your email address will not be published. Required fields are marked *