Sudo rm usr/bin/python3 rm usr/bin/python3 operation not permitted

I just upgraded my macbook from Mojave to Catalina, and after that, I upgraded brew as well. The result is, now I have two python3 binaries:

qxu@xqiang-mac-1:~$ which python3
/usr/local/bin/python3
qxu@xqiang-mac-1:~$ /usr/local/bin/python3 -V
Python 3.7.6
qxu@xqiang-mac-1:~$ whereis python3
/usr/bin/python3
qxu@xqiang-mac-1:~$ /usr/bin/python3 -V
Python 3.7.3

Wanted to delete the 3.7.3 version, but it didn't allow me:

qxu@xqiang-mac-1:~$ sudo rm -rf /usr/bin/python3
Password:
rm: /usr/bin/python3: Operation not permitted

So, there is no way to delete it?

By the way, only python2.7 libs could be found in /usr/lib, but not those of python3.7.3.

qxu@xqiang-mac-1:/usr/lib$ ll *python*
lrwxr-xr-x  1 root  wheel  18 Feb 12 09:49 libpython.dylib -> libpython2.7.dylib
lrwxr-xr-x  1 root  wheel  68 Feb 12 09:49 libpython2.7.dylib -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/Python
lrwxr-xr-x  1 root  wheel  75 Feb 12 09:49 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
qxu@xqiang-mac-1:/usr/lib$ ll /System/Library/Frameworks/Python.framework/Versions
total 0
lrwxr-xr-x   1 root  wheel    3 Feb 12 09:53 2.3 -> 2.7
lrwxr-xr-x   1 root  wheel    3 Feb 12 09:53 2.5 -> 2.7
lrwxr-xr-x   1 root  wheel    3 Feb 12 09:53 2.6 -> 2.7
drwxr-xr-x  10 root  wheel  320 Feb 25 12:03 2.7
lrwxr-xr-x   1 root  wheel    3 Feb 12 09:53 Current -> 2.7

There is /usr/local/lib/python3.7, but it seems that was installed together with 3.7.6 version, since /usr/local/bin is the location of the newer 3.7.6 binary?

qxu@xqiang-mac-1:~$ ll -d /usr/local/lib/*python*
drwxr-xr-x  3 qxu  admin  96 Mar 10 11:30 /usr/local/lib/python3.7

I am trying to remove all my python for reinstall them properly. I have check lot of stack overflow topic, and now I am at this point :

when I am doing

which python3

I have :

/usr/bin/python3

also, doing

ls -l /usr/bin/python*

give :

lrwxr-xr-x  1 root  wheel     75  4 avr  2020 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     82  4 avr  2020 /usr/bin/python-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x  1 root  wheel     75  4 avr  2020 /usr/bin/python2 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     75  4 avr  2020 /usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     82  4 avr  2020 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x  1 root  wheel  31488 10 jul 00:26 /usr/bin/python3
lrwxr-xr-x  1 root  wheel     76  4 avr  2020 /usr/bin/pythonw -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x  1 root  wheel     76  4 avr  2020 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

so clearly my last python3 to remove is : /usr/bin/python3

but when I am doing :

rm python3

I have the question :

override rwxr-xr-x  root/wheel restricted,compressed for python3? y       
rm: python3: Operation not permitted

and here I am completely block, what is the next step ?

I am doing that because that point on a python3.8 (install by brew) and what I want is a python3.7 so if you have a better solution than delete this version to reinstalle 3.7 I am also open to a solution, I am stuck with this issue

thanks

asked Oct 9, 2020 at 19:01

1

A followup on this post from 2022. I meet the same problem today. I did my research on the Internet and experimented all of those on my own. Unfortunately, none succeeds. All I can do now is to summarize those for the latecomers, and please let me know if a good solution comes up.


First I tried is the sudo method. Which gives the same "Operation not permitted" error. Which is weird. Some posts accuse the system as I am also using MacOS. I am not sure if that is also the case of kilag. Anyway, as a response from ls -ld /usr/bin, we can see the operation should be allowed:

drwxr-xr-x  1012 root  wheel  32384  9 May 14:30 /usr/bin

There is also a post mentioning flags which can be revealed by ls -lO. Their programs are successfully deleted after changing the flags by chflags. However, as ls -lO gives restricted, compressed flag for python3 directory which is not even defined in chflags. I pause there.

answered Aug 5 at 5:08

sudo rm /usr/bin/python3

or

sudo rm -r usr/bin/python3

Andronicus

24.6k17 gold badges47 silver badges83 bronze badges

answered Oct 9, 2020 at 19:04

Sudo rm usr/bin/python3 rm usr/bin/python3 operation not permitted