推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
hu5ky
V2EX  ›  Python

win7 下 PY2 和 PY3 怎么做到共存

  •  
  •   hu5ky · Jan 19, 2018 · 6635 views
    This topic created in 3216 days ago, the information mentioned may be changed or developed.

    win7 下 PY2 和 PY3 怎么做到共存,目前工作环境中还有大部分 PY2 的脚本和工具,,但是近年 PY3 的工具,脚本越来越多,怎么在 PY2 能使用的情况下同时支持 PY3 ???

    23 replies  •  2018-01-20 10:07:59 +08:00
    40huo
    40huo
    Jan 19, 2018 via Android
    1
    装了 Python3 不就有 Python launcher 了么,py -2,py -3 切换
    tsoingkam
    tsoingkam
    Jan 19, 2018 via iPhone
    2
    把 py2 和 py3 文件夹内的程序文件改个名字,然后分别添加到环境变量中就行了
    Yemilice
    Yemilice
    Jan 19, 2018
    3
    虚拟环境,virtualenv。
    SuperMild
    SuperMild
    Jan 19, 2018
    4
    miniconda 很省心
    likuku
    likuku
    Jan 19, 2018
    5
    Python 之虚拟环境管理 - 田小计划 - 博客园 : http://www.cnblogs.com/wilber2013/p/4774022.html

    看起来 win 上可以用 pywin:
    pywin : Windows 上 pyenv 的替代品,但是功能相对 pyenv 比较少
    py.exe : Python 3.3 版本以后 Windows 系统自带的启动工具( Python Launcher for Windows ),可以直接在命令行中使用

    virtualenv 也是超棒!

    Python 笔记十一:在 Mac、Linux 和 Windows 的多版本安装 : https://zhuanlan.zhihu.com/p/26009741
    tangwz
    tangwz
    Jan 19, 2018
    6
    pyenv
    Jafee
    Jafee
    Jan 19, 2018
    7
    docker
    iilxy
    iilxy
    Jan 19, 2018❤️1
    8
    装 python3 时记得勾选那个 launcher。
    脚本里第一行写上
    #!python2
    或
    #!python3

    单独运行比如 pip 就写 py -2 -m pip install xxx 或 py -3 -m pip install xxx
    XIVN1987
    XIVN1987
    Jan 19, 2018
    9
    新版 python3 安装时都会带个 py.exe ,,双击.py 文件时使用 py.exe 解释执行此.py 文件

    然后在.py 文件的第一行写上#!python2 或#!python3,,这样 py.exe 根据第一行的内容选择正确的 python 版本
    IllllI
    IllllI
    Jan 19, 2018
    10
    @tsoingkam 8 楼正解 你这样子好像 pip 什么的会出问题的
    tsoingkam
    tsoingkam
    Jan 19, 2018 via iPhone
    11
    @IllllI py2 的用 pip py3 的用 pip3 我之前没用虚拟环境就是这样的
    goofool
    goofool
    Jan 19, 2018
    12
    anaconda
    Applenice
    Applenice
    Jan 19, 2018
    13
    很简单的啊,你先都安装,
    windows 下
    启动用:py -2 或 py -3,需要 pip 的时候:py -2 -m pip install xxx 或 py -3 -m pip install xxx,
    嫌弃麻烦就学着使用 anaconda。
    linux 下用 pyenv+virtualenv 也行,anaconda 也行。这东西百度下来不是一堆的嘛
    dzxindex
    dzxindex
    Jan 19, 2018 via iPhone
    14
    anaconda 不错
    XIVN1987
    XIVN1987
    Jan 19, 2018
    15
    如果不做科学计算或数据分析的话,不建议 anaconda,,安装包 500 多 M,,装完可能有 3 个 G 了吧,,绝大多数包可能永远都用不到,,

    anaconda 的精简版 miniconda 倒可以试试
    fy
    fy
    Jan 19, 2018
    16
    1. 安装 anaconda3 作为 py3 且为默认 python,不省那么一点空间,省心
    2. 装一个 py2,然后将其 python.exe 改名 python2.exe ,我现在 py2 很少用了
    ysc3839
    ysc3839
    Jan 19, 2018
    17
    @tsoingkam @fy 不建议改名,我的做法是创建个 symlink。
    flipped123
    flipped123
    Jan 19, 2018
    18
    https://segmentfault.com/a/1190000005068355
    超级详细的,图文说明
    joyc
    joyc
    Jan 19, 2018 via Android
    19
    需要 pip install pipenv 啊
    fy
    fy
    Jan 19, 2018
    20
    @ysc3839 #17 这个办法简单好用啊,用了好几年也没出什么问题。现在所有脚本都已经是 py3 了。
    hu5ky
    hu5ky
    OP
    Jan 19, 2018
    21
    @Applenice 要是命令能用我也不纠结了,,我这里失败了 0.0.
    Mavious
    Mavious
    Jan 19, 2018 via iPhone
    22
    我也困在双版本共存问题上。我简单粗暴的用 2 台电脑解决了此问题。
    主要是一些方便的工具,很古老很经典(譬如 DeDRM tools ),年久失修了,只支持 2,没法子,搞了个破电脑运行 2 代脚本
    asuraa
    asuraa
    Jan 20, 2018 via iPhone
    23
    用 pyenv ?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1716 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 16:08 · PVG 00:08 · LAX 08:08 · JFK 11:08
    ♥ Do have faith in what you're doing.