您的位置:首页 > 编程语言 > Python开发

多版本python共存的解决方案

2016-07-22 23:06 519 查看

多版本python共存的解决方案

多版本python共存的解决方案
不同版本python切换的方法

多版本python共存下使用pip

不同版本python切换的方法

利用Windows Launcher

py -2.7

py -3

py -3 script.py


在python file头添加Unix-style top-of-script comments,如

#!python2

#!/usr/bin/python2.7

#!/usr/bin/env python3


修改Windows 环境变量PATH设置

系统->高级系统设置->环境变量->path->编辑

然後去手動把 python27下面的python.exe改成python2.exe

python35下面的python.exe改成python3.exe

在CMD输入
python2
运行python2,输入python3运行python3

多版本python共存下使用pip

py -2 -m pip install XXXX
py -3 -m pip install XXXX


原理command-line

python [-bBdEhiIOqsSuvVWx?] [-c command | -m module-name | script | - ] [args]

-m

Search sys.path for the named module and execute its contents as the
__main__
module.

Since the argument is a module name, you must not give a file extension (.py). The module-name should be a valid Python module name, but the implementation may not always enforce this (e.g. it may allow you to use a name that includes a hyphen).

Package names (including namespace packages) are also permitted. When a package name is supplied instead of a normal module, the interpreter will execute
<pkg>.__main__
as the main module. This behaviour is deliberately similar to the handling of directories and zipfiles that are passed to the interpreter as the script argument.

所以
py -3 -m pip
会运行
C:\Python34\Lib\site-packages\pip
路径下的
__main__.py
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python