我将首先声明我已经搜索过这个问题,并在这里找到了完全相同的问题(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