推荐学习书目
› 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
V2EX  ›  Python

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

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

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

    有些要共享的比如 ipython 那个配置文件可能会有 2/3 兼容性问题,改一下也很容易。
    feikaras
    feikaras
    Oct 9, 2015
    29
    brew 出来的,还有 apt 出来的,本身就是分开放的。
    Tetsuchou
    Tetsuchou
    Oct 10, 2015
    30
    就直接在 PyCharm 里面管理了...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1592 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 69ms · UTC 23:07 · PVG 07:07 · LAX 15:07 · JFK 18:07
    ♥ Do have faith in what you're doing.