gpt4 book ai didi

python - 运行 *requests* 时出错

转载 作者:太空宇宙 更新时间:2023-11-04 07:37:24 24 4
gpt4 key购买 nike

使用此处的说明在 OSX 10.10 上安装了 Python/Pip http://docs.python-guide.org/en/latest/starting/install/osx/

只有安装才能访问 Pip

使用pip install requests安装的请求

运行脚本

import requests

feed_url = 'http://www.mylocation.com/the_data'

#grab xml from URL
r = requests.get(feed_url)
r.text

print r

错误是

Traceback (most recent call last):
File "get_all_listings.py", line 1, in <module>
import requests
File "/usr/local/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/local/lib/python2.7/site-packages/requests/utils.py", line 12, in <module>
import cgi
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cgi.py", line 50, in <module>
import mimetools
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
Referenced from: /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

otool -L $(which python) 的输出

/usr/local/bin/python:
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

最佳答案

python 指向了错误的版本

通过运行 hash -d python 修复

关于python - 运行 *requests* 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31599700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com