_02python基础_如何共存python2 &python3 Python 2 与 Python 3 共存

安装 Python 3.3 以上的版本时,Python会在C:Windows文件夹下安装启动器py.exe。双击脚本调用的就是这个程序:
_02python基础_如何共存python2 &python3
Python 2 与 Python 3 共存

如果系统中同时存在 Python 2 和 Python 3,可用它指定版本来运行代码:

py -2 helloworld.py
py -3 helloworld.py

2和3即是版本。

每次都添加参数太麻烦,直接在Python脚本第一行指定版本:

#! python3

可以双击,也可以命令行运行:

py helloworld.py

如果没有在首行指定版本而用上述命令运行或双击,则默认调用Python 2

使用easy instll:

py -2 setup.py instll
py -3 setup.py install

如果没有在首行指定版本而用上述命令运行或双击,则默认调用Python 2

使用pip:

py -2 -m pip install requests
py -3 -m pip install requests

-m pip 表示运行 pip 模块

原有的pythonpip命令仍然有效,默认执行哪一个版本呢?看环境变量中路径的先后次序。

C:Python34;C:Python34Scripts;C:Python27;C:Python27Scripts;


扫码关注QQ交流群

_02python基础_如何共存python2 &python3
Python 2 与 Python 3 共存