gpt4 book ai didi

python - Mac OS X El Capitan - Scrapy/Python 导入错误 : cannot import name xmlrpc_client

转载 作者:太空狗 更新时间:2023-10-29 21:09:42 25 4
gpt4 key购买 nike

我正在尝试在 Mac OS X El Capitan 上使用 Scrapy。我安装了 zsh,并尝试了所有可以在网上找到的方法来解决此问题。我也看过Scrapy throws ImportError: cannot import name xmlrpc_client无法解决我的问题!

通过 brew 安装 Python 并添加“pip install scrapy”:

➜  DriverEBV  which python
/usr/local/bin/python

我的 .zshrc 包含以下行:

export PATH=/usr/local/bin:$PATH
export PYTHONPATH="/Library/Python/2.7/site-packages"

这是我得到的错误:

➜  DriverEBV  scrapy runspider DriverEBV.py
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 7, in <module>
from scrapy.cmdline import execute
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 48, in <module>
from scrapy.spiders import Spider
File "/Library/Python/2.7/site-packages/scrapy/spiders/__init__.py", line 10, in <module>
from scrapy.http import Request
File "/Library/Python/2.7/site-packages/scrapy/http/__init__.py", line 12, in <module>
from scrapy.http.request.rpc import XmlRpcRequest
File "/Library/Python/2.7/site-packages/scrapy/http/request/rpc.py", line 7, in <module>
from six.moves import xmlrpc_client as xmlrpclib
ImportError: cannot import name xmlrpc_client

当我运行“pip install scrapy”时,这就是我看到的:

➜  DriverEBV  pip install scrapy
Requirement already satisfied (use --upgrade to upgrade): scrapy in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /Library/Python/2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): queuelib in /usr/local/lib/python2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /usr/local/lib/python2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): w3lib>=1.8.0 in /Library/Python/2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): lxml in /Library/Python/2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): Twisted>=10.0.0 in /Library/Python/2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/lib/python2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): service-identity in /Library/Python/2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): cryptography>=0.7 in /usr/local/lib/python2.7/site-packages (from pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): zope.interface>=3.6.0 in /usr/local/lib/python2.7/site-packages (from Twisted>=10.0.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): characteristic>=14.0.0 in /Library/Python/2.7/site-packages (from service-identity->scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyasn1-modules in /Library/Python/2.7/site-packages (from service-identity->scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyasn1 in /Library/Python/2.7/site-packages (from service-identity->scrapy)
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): enum34 in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): ipaddress in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): idna>=2.0 in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): cffi>=1.1.0 in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/local/lib/python2.7/site-packages (from cffi>=1.1.0->cryptography>=0.7->pyOpenSSL->scrape)

有人能帮帮我吗?

最佳答案

我对安装在 /Library/Python 目录中的 Mac OS X 系统 Python 库感到痛苦。对我来说效果很好的是 MacPorts 和 virtualenv 的组合:

  1. 安装 MacPorts

  2. 从 MacPorts 安装 Python、pip 和 virtualenv:

    /opt/local/bin/port install python27
    /opt/local/bin/port install py27-pip
    /opt/local/bin/port install py27-virtualenv
  3. 设置虚拟环境:

    /opt/local/bin/virtualenv-2.7 myenv
  4. 激活 virtualenv(不要忘记 pip !)

    . myenv/bin/activate
  5. 安装scrapy

    pip install scrapy

这样,系统 Python 库就不会受到影响,您可以安装任何您喜欢的包,而无需删除或升级现有包。

关于python - Mac OS X El Capitan - Scrapy/Python 导入错误 : cannot import name xmlrpc_client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33929169/

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