Mac Mountain Lion/Macports/Python27:已安装,已激活,但已导入

2024-04-26 11:55:22 发布

您现在位置:Python中文网/ 问答频道 /正文


我安装了Macports和Python27。激活它,但它不工作?有什么问题吗? 我甚至删除了brew和以前的端口安装,并在重新安装新副本之前重新启动。在

提前谢谢。

macbook-pro-15:~ MR$ sudo port select --list python
    Available versions for python:
        none
        python25-apple
        python26-apple
        python27 (active)
        python27-apple
    macbook-pro-15:~ MR$ python
    Traceback (most recent call last):
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 548, in <module>
        main()
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 530, in main
        known_paths = addusersitepackages(known_paths)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 266, in addusersitepackages
        user_site = getusersitepackages()
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 241, in getusersitepackages
        user_base = getuserbase() # this will also set USER_BASE
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 231, in getuserbase
        USER_BASE = get_config_var('userbase')
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 516, in get_config_var
        return get_config_vars().get(name)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 449, in get_config_vars
        import re
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 105, in <module>
        import sre_compile
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_compile.py", line 14, in <module>
        import sre_parse
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 17, in <module>
        from sre_constants import *
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_constants.py", line 18, in <module>
        from _sre import MAXREPEAT
    ImportError: cannot import name MAXREPEAT

Tags: inpyimportliblocallinelibrarysite
2条回答

我也有同样的问题。最后对我有用的是通过MacPorts卸载并重新安装python。在

> sudo port uninstall python27
> sudo port install python27
> sudo port select  set python python27

此已安装Python 2.7.5 (default, Aug 1 2013, 01:01:17)。在

卸载并重新安装后,请确保注销shell并打开新的shell。老炮弹仍然会遇到同样的问题。在

这个问题是由于bash兑现了以前发出的命令的路径。在

捷径是:

$ hash -d python
$ python

长话短说:为了提高效率,bash缓存了以前启动的路径 命令。通过macports安装Python之后,如果您的系统Python已经被bash缓存,那么调用python仍将调用系统Python(尽管which python输出macports Python版本)

^{pr2}$

相关问题 更多 >