1

Im working with python 2.7 and I was having import errors with random, So I checked the path and noticed it was using random.pyc instead of random.py

I tried to remove the file but it won't work.

sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.pyc

and rm -R gives me this error even when I say y

sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.pyc
override rw-r--r--  root/wheel restricted,compressed for /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.pyc? y
rm: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.pyc: Operation not permitted

What should I do?

Edit: My whole "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/" is full of .pyc and .pyo files and import doesn't work on any of them (unless I use idle)

1
  • What version of macOS? It's probably SIP if you're on El Capitan or later.
    – Spiff
    Jul 26 '17 at 2:52
4

First: This is normal. .pyc files are precompiled Python files. They contain the same data as the .py files adjacent to them. If you are having problems with the random module, you are probably doing something else wrong, and you should probably ask a question about your code on Stack Overflow.

More generally: You cannot, and should not, modify files under the /System directory. They are part of the operating system -- modifying them will cause your computer to work incorrectly.

macOS prevents system files from being modified (other than by system updates) using a mechanism called System Integrity Protection, or SIP. It is possible to disable SIP, but this should generally not be necessary, even for developers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.