V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
V2EX  ›  Python

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

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

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

    有些要共享的比如 ipython 那个配置文件可能会有 2/3 兼容性问题,改一下也很容易。
    feikaras
        29
    feikaras  
       2015-10-09 05:21:25 +08:00
    brew 出来的,还有 apt 出来的,本身就是分开放的。
    Tetsuchou
        30
    Tetsuchou  
       2015-10-10 18:03:47 +08:00
    就直接在 PyCharm 里面管理了...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2880 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:50 · PVG 22:50 · LAX 07:50 · JFK 10:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.