0

我将首先声明我已经搜索过这个问题,并在这里找到了完全相同的问题(ImportError: No module named 'requests')但这对我没有帮助。

我在 osx(山狮)上使用 macports。我已经成功安装并运行了一些脚本,没有任何问题。

从 macports 页面,我已经requests通过详细说明的方法进行了安装,据我所知,它已成功安装:

daves-mbp:~ Dave$ port search requests
arpwatch @2.1a15 (net)
    Monitor ARP & RARP requests

http_ping @29jun2005 (net, www)
    Sends HTTP requests every few seconds and times how long they take

httping @2.0 (net, www)
    Ping-like tool for http-requests

py-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py26-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py27-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py31-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py32-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py33-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

webredirect @0.3 (www)
    small webserver which redirects all requests

Found 10 ports.

我有 python 2.7,所以我通过以下方式安装了它:

daves-mbp:~ Dave$ sudo port install py27-requests
Password:
--->  Computing dependencies for py27-requests
--->  Fetching archive for py27-requests
--->  Attempting to fetch py27-requests-1.2.3_0.darwin_12.noarch.tbz2 from http://jog.id.packages.macports.org/macports/packages/py27-requests
--->  Attempting to fetch py27-requests-1.2.3_0.darwin_12.noarch.tbz2.rmd160 from http://jog.id.packages.macports.org/macports/packages/py27-requests
--->  Installing py27-requests @1.2.3_0
--->  Activating py27-requests @1.2.3_0
--->  Cleaning py27-requests
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.
daves-mbp:~ Dave$ 

我认为这看起来不错。使用 macports 在使用它之前我还需要做些什么吗?我认为python setup.py install(在上述帖子中)可能已经解决了我的问题,但是,当我requests在我的文件系统中搜索时,唯一的引用被埋在路径中(macports 说是用户安装模块的商店。此外,还有其中没有 setup.py 或其父目录。

我已经重新启动了我的终端窗口(之前解决了另一个问题),但在这里没有任何区别。

任何帮助表示赞赏

编辑:

which python报告 /opt/local/bin/python

python解释器DID报告的第一行:daves-mbp:~ Dave$ python Python 2.7.2 (default, Jun 20 2012, 16:23:33) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang -418.0.60)] 在达尔文

但现在我已经做了一些事情,它正在响应新的错误:

daves-mbp:~ Dave$ 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
4

1 回答 1

0

在试图解决这个问题时,我已经破坏了 python,最终我又让它恢复了。

我想最初我没有运行其中一个port select --set...命令。一旦我意识到可能是这种情况,我就这样做了,但这会在顶部产生错误。MAXREPEATS,也许是循环引用?不知道。

我已阅读此处(macports 未将 python_select 放入 /opt/local/bin)和此处(如何从 OSX Leopard 卸载 python 以便我可以使用 MacPorts 版本?)关于该--set命令不起作用并尝试sudo port select python python26(我使用 python27) 代替。

我检查了 PATH 并且没有出现 python,所以我也更新了它。

我拿回了我的 python 解释器,imports requests现在可以正常工作了。

我认为在这一切结束时,有两个错误:

  1. 我使用--set而不是较新的命令,并且

  2. 我的路径没有设置

编辑:实际上,经过更多调试,我发现错误出现在脚本的第一行,我已经定义了要使用的python(这是默认的苹果,不包括模块)。一旦我更新了 shebang 线,它就起作用了。

于 2013-07-16T00:31:37.880 回答