你电脑上 python2 和 python3 是怎么和平共处的? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
phithon
5.05D

你电脑上 python2 和 python3 是怎么和平共处的?

  •  
  •   phithon
    phith0n Oct 8, 2015 6493 views
    This topic created in 3855 days ago, the information mentioned may be changed or developed.
    RT 。电脑是 mac 。
    平时用 python2 用的多,但 python3 也用。
    pip 安装的全局库全是 python2 的。
    用 python3 的时候,每次用都得 virtualenv 。
    但有些就运行个小脚本,几行的,不可能也专门为其创建一个 env 呀。。
    大家是怎么处理的?
    30 replies    2015-10-10 18:03:47 +08:00
    mathgl
        1
    mathgl  
       Oct 8, 2015 via Android
    我自己编译了 py2 py3 。同时用也没什么问题。
    phithon
        2
    phithon  
    OP
       Oct 8, 2015
    @mathgl
    我主要是说第三方库的问题。。
    比如我怎么给 python3 安装第三方库?
    013231
        3
    013231  
       Oct 8, 2015
    你完全可以装 Python 3 的全局库. 和 2 不会互相影响.
    ljcarsenal
        4
    ljcarsenal  
       Oct 8, 2015 via Android
    mac 不知道 linux 上命令行是 Python3 pip3 这样的
    phithon
        5
    phithon  
    OP
       Oct 8, 2015
    @013231 具体怎么装,我一直没搞清楚(用 pip install 就默认去 py2 了)
    013231
        6
    013231  
       Oct 8, 2015   1
    @phithon pip3 install
    phithon
        7
    phithon  
    OP
       Oct 8, 2015
    @ljcarsenal mac 这样执行报错了。。
    phithon
        8
    phithon  
    OP
       Oct 8, 2015
    @013231 好,我试下哈
    WalkingEraser
        9
    WalkingEraser  
       Oct 8, 2015
    windows 和 linux 表示想用哪个就用哪个,并没有冲突,因为其实就是个环境变量的事情
    013231
        10
    013231  
       Oct 8, 2015
    @phithon 你的 Python 3 装 pip 了吗?
    phithon
        11
    phithon  
    OP
       Oct 8, 2015
    @013231 装了,成了~感谢!
    Owenjia
        12
    Owenjia  
       Oct 8, 2015 via Android   1
    pip3 ,或者 python3 -m pip
    Gentoo 的话还可以设置 PYTHON_TARGETS 然后用 Portage 装
    ericls
        13
    ericls  
       Oct 8, 2015
    我从来没有在没有 virtualenv 的环境下自己运行过 python 脚本 (除了当计算器用)
    ericls
        14
    ericls  
       Oct 8, 2015
    @WalkingEraser OS X 也是一样
    mathgl
        15
    mathgl  
       Oct 8, 2015 via Android
    @phithon pip3 没发现有什么问题。
    haroldwu
        16
    haroldwu  
       Oct 8, 2015 via Android
    用 anaconda 管理的路~
    blueset
        17
    blueset  
       Oct 8, 2015
    python && pip
    python3 && pip3
    zander
        18
    zander  
       Oct 8, 2015   1
    pip3 啊,没问题的。
    homebrew install python python3
    pip install
    pip3 install
    janxin
        19
    janxin  
       Oct 8, 2015
    pyenv
    darouwan
        20
    darouwan  
       Oct 8, 2015
    完全没影响啊~我何止是 Python2 和 3 啊,还有 2 的 32bit ,和 3 的 32bit ,还有 Anaconda3
    pheyer
        21
    pheyer  
       Oct 8, 2015
    pyenv+1
    everettjf
        22
    everettjf   Oct 8, 2015
    pyenv+1
    tmdwex06895
        23
    tmdwex06895  
       Oct 8, 2015
    pyenv
    Delbert
        24
    Delbert  
       Oct 8, 2015 via Android
    pycharm ……切换……
    s00s
        25
    s00s  
       Oct 8, 2015
    ln -s /usr/bin/python3 /usr/local/bin/python3
    ln -s /usr/bin/python /usr/local/bin/python2
    adaibee
        26
    adaibee  
       Oct 8, 2015
    mapleray
        27
    mapleray  
       Oct 8, 2015
    brew install python3 python2
    本身 3 和 2 就是分开的,使用的时候 python3 python2 就行,安装库使用 pip3 pip2 ,具体看它链接到哪里。不过一般还是用 virtualenv 和 virtualenvwrapper 吧,尽量不共用系统的 Lib 。
    ibigbug
        28
    ibigbug  
       Oct 8, 2015
    pip2 | pip3 install xxx

    大部分库没问题,都是隔离的。

    有些要共享的比如 ipython 那个配置文件可能会有 2/3 兼容性问题,改一下也很容易。
    feikaras
        29
    feikaras  
       Oct 9, 2015
    brew 出来的,还有 apt 出来的,本身就是分开放的。
    Tetsuchou
        30
    Tetsuchou  
       Oct 10, 2015
    就直接在 PyCharm 里面管理了...
    About     Help     Advertise     Blog     API     FAQ     Solana     1136 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 138ms UTC 18:12 PVG 02:12 LAX 11:12 JFK 14:12
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86