2015-11-26 20 views
8

Mac OS X El CapitanでScrapyを使用しようとしています。私はzshをインストールしており、私はこの問題を解決するためにオンラインで見つけることができるすべてを試しました。私もScrapy throws ImportError: cannot import name xmlrpc_clientを見て、私の問題を解決できませんでした!Mac OS X El Capitan - Scrapy/Python ImportError:名前をインポートできませんxmlrpc_client

Pythonは "scrapyをインストールPIP" BREW経由でインストールして、コメントを追加しました:

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

私を助けることができる人は誰ですか?

+0

[Scrapy throws ImportError:duplicate of name xmlrpc \ _client]をインポートできません(http://stackoverflow.com/questions/30964836/scrapy-throws-importerror-cannot-import-name-xmlrpc-client) – eLRuLL

+2

残念ながら重複私はあなたが投稿した記事で議論されたすべてを試しました。だから私は、オンラインで利用可能だった他のすべてをほとんど侵入していないものからほとんど侵入したものにしようとしました。 –

+0

なぜここにpythonパスを設定しますか? – cel

答えて

1

何がアンインストール6とscrapyにして、再度をインストールする私を助け:

pip uninstall six 
pip uninstall scrapy 

pip install six 
pip install scrapy 

実行sudoで、必要な場合。


それとも、あなたはまた、6とscrapyをアップグレードしてみてくださいすることができます

pip install --upgrade scrapy 
pip install --upgrade six 
+0

コマンドラインでscrapyを実行すると問題が解決すると思います。 PyCharmで実行しているときに、このエラーが発生します。すべての提案を解決するには? –

+0

@GuyDhaher設定の中のプロジェクトインタプリタは正しいものですか? (私はこの例では、デフォルトのpythonのインストールでなければならないと信じています) – mkaran

2

私は/Library/PythonディレクトリにインストールされているMac OS XシステムのPythonライブラリをいじくるの痛みが、何もなかったしました。どのような私のためによく働いたことのMacPortsとvirtualenvの組み合わせである:

/opt/local/bin/port install python27 
/opt/local/bin/port install py27-pip 
/opt/local/bin/port install py27-virtualenv 
  • セットアップvirtualenvの:

    1. MacPorts

    2. パイソン、ピップ、およびMacPortsのからvirtualenvのをインストールをインストールします。

      /opt/local/bin/virtualenv-2.7 myenv 
      
    3. アクティベートvirtualenvの(ドットを忘れないように!)

      . myenv/bin/activate 
      
    4. は、この方法でscrapy

      pip install scrapy 
      

    をインストールし、システムのPythonライブラリはそのままであり、あなたは、あなたがなしで好きなパッケージをインストールすることができます既存のパッケージを削除またはアップグレードする必要があります。

  • +0

    私はコマンドラインでscrapyを実行しているときに私の問題を解決したと思います。 PyCharmで実行しているときに、このエラーが発生します。すべての提案を解決するには? –

    +0

    PyCharmは現在virtualenvをサポートしているようです。 [Project Interpreter](https:// www)を介して[既存のvirtualenvを追加する(https://www.jetbrains.com/help/pycharm/2016.1/adding-existing-virtual-environment.html) .jetbrains.com/help/pycharm/2016.1/project-interpreter.html)。お役に立てれば。 –

    +0

    ええ、私はこのコメントを投稿した後にそれを考え出しました。上記の情報をありがとう、賞金を授与 –

    -1

    私はOS X上の最適なソリューションは "システムのpythonを使用しないでください"と思っています。それは人生を楽にします。 This linkはこれを行う方法を示しています。

    There’s a known issue that prevents pip from updating system packages. This has to be addressed to successfully install Scrapy and its dependencies. Here are some proposed solutions:

    (Recommended) Don’t use system python, install a new, updated version that doesn’t conflict with the rest of your system. Here’s how to do it using the homebrew package manager:

    1. Install homebrew following the instructions in http://brew.sh/
    2. Update your PATH variable to state that homebrew packages should be used before system packages (Change .bashrc to .zshrc accordantly if you’re using zsh as default shell):

    echo "export PATH=/usr/local/bin:/usr/local/sbin:$PATH" >> ~/.bashrc

    1. Reload .bashrc to ensure the changes have taken place:

    source ~/.bashrc

    1. Install python:

    brew install python

    1. Latest versions of python have pip bundled with them so you won’t need to install it separately. If this is not the case, upgrade python:

    brew update; brew upgrade python

    +0

    この方法を使って "Scrapy"をインストールしてインポートできますか? – cpburnz

    +0

    @cpburnz問題ありません。それは私のために完璧に動作します。 –

    0

    pipでアンインストールしてから、easy_installコマンドを使用して再インストールしてください。私は別のpythonモジュールで同じ問題を抱えていました。この方法でMac OS X El Capitanで私の問題を解決しました。

    関連する問題