Python3 solves OSError: [Errno 30] Read-only file system error under MacOS Big Sur

After MacOS was upgraded to Big Sur, I found that the file could not be written to the disk using the os module of Python3. It will be reported OSError: [Errno 30] Read-only file systemerror.

1. Analysis error

Since there is an error, we will analyze the error!

After understanding, after Mac OS 10.11, Apple introduced a kernel protection measure SIP(System Integrity Protection), also known as the Rootless mode mechanism , in order to improve the security of the system environment .

In SIPcase the mechanism, the system will default lock /system, /sbin, /usrthree directories, even if the switch to the rootuser can only see, can not perform other operations.

SIP It can effectively prevent malicious programs from damaging the computer, so it is recommended to keep it turned on.

For more detailed understanding, please check https://eclecticlight.co/2020/06/25/big-surs-signed-system-volume-added-security-protection .

Solve the problem

Then understand the problem, to address the issue, since it is SIPa result of that we have from the SIPstart.

View SIPstatus.

MacBook:~ zhangyi$ csrutil status
System Integrity Protection status: open.

Found SIPin the open state, it will be SIPdisabled.

MacBook:~ zhangyi$ csrutil disable
csrutil: This tool needs to be executed from Recovery OS.

When I entered the command, I found that this command can only be executed in recovery mode.

。。。

What about entering Apple's recovery mode?

First, restart the computer, the Apple icon dark, while holding down Command+Rinto recovery mode.

Enter the recovery page, open the terminal.

[Top Menu Bar] -> [Utilities] -> [Open Terminal]
Insert picture description here
and execute the disable command.

csrutil disable 

Insert picture description here
Finally, restart it.

reboot

This general to step on it, if you want to reopen SIPalso need to be performed in recovery mode.

csrutil enable

If you don't solve it, remember to try this command.

sudo mount -uw /

Mount the root directory.

However, there may be an error due to insufficient permissions:

mount_apfs: volume could not be mounted: Permission denied
mount: / failed with 66

mount_apfs: volume could not be mounted: Operation not permitted
mount: / failed with 77

Guess you like

Origin blog.csdn.net/yilovexing/article/details/113760937