I just switched over to Python3 and I can't se

2019-08-18 02:42发布

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

2条回答
相关推荐>>
2楼-- · 2019-08-18 03:14

The author of the suggestion that solved my problem deleted their post already, but the command sudo ln -s /usr/bin/python /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4 did the trick.

查看更多
一夜七次
3楼-- · 2019-08-18 03:25

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.

查看更多
登录 后发表回答