The "OSError: [Errno 30] Read-only file system" occurs when you pass a
non-existent path to an
os method or try to write to a read-only directory.
To solve the error, make sure that the path you've passed to the method is correct and points to a directory that exists and to which you have the necessary permissions to write.
For example, in the following code sample, the error is raised because the
/User directory doesn't exist.
import os # OSError: [Errno 30] Read-only file system: '/User' os.mkdir('/User/bobbyhadz/Desktop/New Folder/')
If you are on macOS, the directory is called
os.mkdir() method tries to create a directory called
/User in the root
/ and doesn't have the necessary permissions to do so because the
/ directory is read-only.
Make sure the path you are passing to the
os method is writable, correct and
/, you won't be able to because the path is read-only.
You can try to write the files to a different directory to which you have permissions to write.
If you don't have the necessary permissions to write to the directory, you can
chmod -R 755 /path/to/your/directory
If that doesn't work, you can try using looser permissions.
chmod -R 777 /path/to/your/directory
If the directory is writable, you shouldn't get the read-only file system error.
If you don't know the absolute path to your directory:
pwdcommand to print the absolute path to the working directory.
inputdirectory in Kaggle is read-only
Note that the
input directory in Kaggle is read-only, so you can't write to
You have to write your files to the
The path of the
working directory is
Here is an example that writes to the
import zipfile zip_file_path = '/kaggle/input/my-project/training.zip' target_directory = '/kaggle/working/training' with zipfile.ZipFile(zip_file_path, 'r') as zip_file: zip_file.extractall(target_directory)
/kaggle/input directory is only used for reading files.
The directory is read-only, so no files can be written to it.
/kaggle/working directory is used to store your output files (e.g.
If you got the error when using AWS Lambda, make sure to only write to the
AWS Lambda's file system is read-only except for the
If you want to write to the file system in a lambda function, make sure to
modify your code to write to a path that's inside the
Make sure to use an absolute path when writing to the
/tmp directory, e.g.
If you're trying to run a pipeline in AzureML, try to add the
/tmp/ prefix to
the path, e.g.
"/tmp/" + key.
You can learn more about the related topics by checking out the following tutorials: