Mac OS X El Capitan - Scrapy / Python ImportError:无法导入名称xmlrpc_client

时间:2015-11-26 01:22:42

标签: python macos scrapy pip

我正在尝试在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

当我跑步&#34; pip install scrapy&#34;现在这就是我所看到的:

➜  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)

有人能帮助我吗?

4 个答案:

答案 0 :(得分:2)

我对/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. 设置virtualenv:

    /opt/local/bin/virtualenv-2.7 myenv
    
  4. 激活virtualenv(别忘了点!)

    . myenv/bin/activate
    
  5. 安装scrapy

    pip install scrapy
    
  6. 这样,系统Python库不受影响,您可以安装任何您喜欢的软件包,而无需删除或升级现有软件包。

答案 1 :(得分:1)

帮助我的是卸载6并scrapy,然后重新安装

pip uninstall six
pip uninstall scrapy

pip install six
pip install scrapy

如有必要,请使用sudo运行。

或者,你也可以尝试升级六和scrapy:

pip install --upgrade scrapy
pip install --upgrade six

答案 2 :(得分:0)

尝试通过pip卸载,然后使用easy_install命令重新安装。我在使用另一个python模块时遇到了同样的麻烦,这样就可以解决我在Mac OS X El Capitan上的问题。

答案 3 :(得分:-1)

我认为OS X的最佳解决方案应该是&#34;不要使用system python&#34;。它会让生活更轻松。 This link显示了如何执行此操作。

  

有一个已知问题阻止pip更新系统包。必须解决这个问题才能成功安装Scrapy及其依赖项。以下是一些建议的解决方案:

     

(推荐)不要使用系统python,安装一个与系统其他部分不冲突的新版本。以下是使用自制软件包管理器的方法:

     
      
  1. 按照http://brew.sh/
  2. 中的说明安装自制软件   
  3. 更新您的PATH变量以声明应在系统软件包之前使用自制软件包(如果您使用zsh作为默认shell,则将.bashrc更改为.zshrc):
  4.         

    echo&#34; export PATH = / usr / local / bin:/ usr / local / sbin:$ PATH&#34; &GT;&GT;的〜/ .bashrc

         
        
    1. 重新加载.bashrc以确保已进行更改:
    2.         

      source~ / .bashrc

           
          
      1. 安装python:
      2.         

        brew install python

             
            
        1. 最新版本的python将pip与它们捆绑在一起,因此您无需单独安装它。如果不是这种情况,请升级python:
        2.         

          brew更新; brew升级python