多版本python共存的解决方案

多版本python共存的解决方案

不同版本python切换的方法

  1. 利用Windows Launcher

    py -2.7
    
    py -3
    
    py -3 script.py
  2. 在python file头添加Unix-style top-of-script comments,如

    
    #!python2
    
    
    
    #!/usr/bin/python2.7
    
    
    
    #!/usr/bin/env python3
    
  3. 修改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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值