Last updated: Apr 11, 2024
Reading time·3 min
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 /Users
.
The os.mkdir()
method tries to create a directory called /User
in the root
directory /
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
complete.
/
, 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
use the chmod
command.
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:
cd
into it.pwd
command to print the absolute path to the working directory.pwd
input
directory in Kaggle is read-onlyNote that the input
directory in Kaggle is read-only, so you can't write to
it.
You have to write your files to the working
directory.
The path of the working
directory is /kaggle/working/
.
Here is an example that writes to the /kaggle/working
directory.
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)
The /kaggle/input
directory is only used for reading files.
The directory is read-only, so no files can be written to it.
The /kaggle/working
directory is used to store your output files (e.g. .txt
,
.csv
, .json
, .xml
, etc).
/tmp
pathIf you get the error when using AWS Lambda, make sure to only write to the
/tmp
path.
AWS Lambda's file system is read-only except for the /tmp
path.
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 /tmp
directory.
Make sure to use an absolute path when writing to the /tmp
directory, e.g.
/tmp/my_file.txt
.
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: