Python Scrapy 使用时报错 cannot import name xmlrpc_client

在使用时处出现下面错误:
Traceback (most recent call last): File “/usr/local/bin/scrapy”, line 7, in from scrapy.cmdline import execute File“/Library/Python/2.7/sitepackages/scrapy/init.py”, line 34, in from scrapy.spiders import Spider File“/Library/Python/2.7/sitepackages/scrapy/spiders/init.py”, line 10, in from scrapy.http import Request File“/Library/Python/2.7/sitepackages/scrapy/http/init.py”, line 12, in from scrapy.http.request.rpc import XmlRpcRequest File“/Library/Python/2.7/sitepackages/scrapy/http/request/rpc.py”, line 7, in from six.moves import xmlrpc_client as xmlrpclib
ImportError: cannot import name xmlrpc_client

主要还是Python的环境变量不对引起的。
解决办法:去改变当前PYTHONPATH(python环境变量)
1.在使用scrapy时现在终端执行下面命令:
export PYTHONPATH=/Library/Python/2.7/site-packages:$PYTHONPATH

2.如果执行上面的命令后,然后执行scrapy命令,不出错就使用下面的命令彻底解决:(注:Linux 里面是 .bashrc 而 Mac 是 .bash_profile)
echo “export PYTHONPATH=/Library/Python/2.7/site-packages:$PYTHONPATH” >> ~/.bash_profile

郝先生

继续阅读此作者的更多文章