python3未配置,我刚刚切换到Python3,但无法将其设置为python的默认版本

When searching for a solution for my problem, all advice points towards just prepending my $PATH variable with the path to that version of Python, but that doesn't help.

Here's my .bash_profile:

PATH="/usr/local/mysql/bin:/bin:/usr/bin:/usr/local/bin:~/bin"

export PATH="~/bin/python/anaconda:/opt/local/bin:/opt/local/sbin:$PATH"

export PATH="/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4:$PATH"

PYTHONPATH="/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4:${PYTHONPATH}

$ which python

/usr/bin/python

>>> import sys

>>> for p in sys.path:

... print(p)

...

/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip

/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4

/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin

/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload

/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages

解决方案

Almost all *nix systems like MacOSX, most Linux distributions, expect python to refer to Python 2; python3 to Python 3. If you change this, something might break badly. Thus even though the PEP 394 talks about the "default" python distribution for python, and that all Python 2 scripts would use python2 in shebang, it is not the fact yet. Many programs expect python to stand for python2.

Furthermore even in such a system you still should prefix your scripts with python3 and explicitly run your Python 3 programs with that command. Just prefix your scripts with something like

#!/usr/bin/env python3

and it should work.

If you are bugged about python 2.7 opening whenever you execute python, do an alias in your .bashrc:

alias python=python3

Also I am not sure if whatever you are doing with PYTHON_PATH is wise; the python interpreter will know where to look for its own libraries without this hackery.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值