2

I'm trying to use scrape on Mac OS X EI, and I have successfully installed scrapy using

pip install scrapy

in the terminal. After that, I met the above problem when I tried to "import scrapy" in the Pycharm:

Traceback (most recent call last):
File "/Users/ziyuan/PycharmProjects/untitled/en.py", line 1, in <module>
import scrape
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

And I have tried everything from Scrapy throws ImportError: cannot import name xmlrpc_client

Specifically, when I tried the highest-voted solution, the second line

sudo rm -rf/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six*

throwed me another problem:

rm: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info: Operation not permitted
rm: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py: Operation not permitted
rm: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc: Operation not permitted

What should I do now? I have searched it in google for a long time and I really have no idea now.

Community
  • 1
  • 1
richard_lzy
  • 31
  • 1
  • 1
  • 5
  • That last `rm` issue is probably caused by El Capitan's SIP "feature". Disabling it should allow you to the files, but I am not sure that'd help in your original problem. – Gustavo Bezerra Feb 26 '16 at 03:46
  • that is a system integrity protect http://stackoverflow.com/questions/32659348/operation-not-permitted-when-on-root-el-capitan-rootless-disabled – panda0 Mar 12 '16 at 07:55

3 Answers3

1

A different way to deal with this problem, rather than highest-voted solution as you mentioned, is using other Python(not the system one) and virtualenv.

But why new Python? Here's an good article for the question. Reasons are easy to find.

And why virtualenv? You can get the point form here.

Furthermore, it's maybe not an good idea to use $ sudo pip (...). Please look at this.

So let's do the recommended way by one of Scrapy's contributor! Look at Mac OS X part: Using Homebrew to install new Python, updated your path variable, ...etc. Although she said using virtualenv is optional, I can only keep ImportError: blahblah.. away in my own virtual environment when using Scrapy.

Eric Tsai
  • 66
  • 1
  • 5
1

After trying several solutions and attempting to work around the six 1.4.1 version, I found this worked:

sudo easy_install --upgrade six
Sam
  • 20,096
  • 2
  • 45
  • 71
norkish
  • 11
  • 3
  • Edit your answer — code into code tags. As a side note, this may be better placed in the comments box — I don't think it is a concise answer to the OP. –  Jul 08 '16 at 19:20
0

Operation not permited means you don't have the permission to remove this. Try sudo rm instead to delete it as a Super User.

Though ideally you shouldn't rm anything from your python, try pip uninstall six instead. However you still need six so you might as well try upgrading it via pip install six --upgrade.

Note that you might have to use pip2 instead of pip because certain systems label it differently.

Granitosaurus
  • 20,530
  • 5
  • 57
  • 82
  • El Capitan adds a feature where root doesn't have permission to modify /System, /bin, /etc, /usr (except /usr/local) – tbodt Jun 28 '16 at 19:30