我首先说明我已经搜索过这个问题,并在这里找到了完全相同的问题(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(默认,2012年6月20日,16:23:33) [达尔文的GCC 4.2.1兼容的Apple Clang 4.0(标签/ 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
答案 0 :(得分:0)
在试图解决这个问题时,我已经打破了python,最终我又重新开始了。
我认为最初我没有运行port select --set...
命令之一。一旦我意识到这种情况可能就是这样,我就这样做了,但这会产生错误。 MAXREPEATS,也许是循环参考?不知道。
我已在此处阅读(macports didn't place python_select in /opt/local/bin)和此处(How do I uninstall python from OSX Leopard so that I can use the MacPorts version?)关于--set
命令无法正常工作并尝试使用sudo port select python python26
(我使用的是python27)。
我检查了PATH并没有出现python,所以我也更新了。
我得到了我的python解释器,现在看起来很低调imports requests
。
我认为最后,有两个错误:
我使用--set
代替新命令,
我的路径未设置
编辑:实际上,经过更多调试后,我发现错误发生在我脚本的第一行,我已经定义了哪个python使用(这是默认的苹果,不包括模块)。一旦我更新了shebang线,它就起作用了。