There is very little difference between the two types. In fact, even the core Python developers agreed that there is no real difference and removed IOError in Python 3 (it is now an alias for OSError). See PEP 3151 - Reworking the OS and IO exception hierarchy:

While some of these distinctions can be explained by implementation considerations, they are often not very logical at a higher level. The line separating OSError and IOError, for example, is often blurry. Consider the following:

>>> os.remove("fff")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] No such file or directory: 'fff'
>>> open("fff")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'fff'

Yes, that's two different exception types with the exact same error message.

For your own code, stick to throwing OSError. For existing functions, check the documentation (it should detail what you need to catch), but you can safely catch both:

try:
    # ...
except (IOError, OSError):
    # handle error

Quoting the PEP again:

In fact, it is hard to think of any situation where OSError should be caught but not IOError, or the reverse.

Answer from Martijn Pieters on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › what’s the difference between ioerror and oserror in python?
What’s the difference between IOError and OSError in python? : r/learnpython
November 11, 2020 - It also says IOError was merged with OSError. There is also a FileNotFoundError for when a file doesn't exist. Note that these are conventions, libraries can raise whatever they want. Your best bet is to read the documentation of the functions you're calling. ... I finished Helsinki's Advanced Programming course and would like to know what some popular courses are that could come after this one. Perhaps about DSA or other. ... Python is so confusing to me.
Discussions

load_file: OSError vs IOError
just a minor point here. Should parmed use OSError or IOError? According to python doc IOError Raised when an I/O operation (such as a print statement, the built-in open() function or a method of a file object) fails for an I/O-related r... More on github.com
🌐 github.com
6
January 11, 2016
How to differentiate different IOErrors?
Sign up · Log in · Reset your password · Create account · Reset password · Create a new account More on forum.nim-lang.org
🌐 forum.nim-lang.org
November 1, 2020
Better communicate that `IOError` and `WindowsError` are just aliases of `OSError` now
Bug report While working on some Windows-related typeshed PRs, I've noticed that some places in docs are very clear about this change. For example: .. versionchanged:: 3.3 :exc:`IOError` used t... More on github.com
🌐 github.com
1
October 7, 2023
python - Dealing with I/O exceptions beyond OSError - Stack Overflow
I have an endless program that needs to write to daily log files. Below is basically my Message class that opens a file at startup and closes/opens a new file daily. Now I'm testing for error handl... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Real Python
realpython.com › ref › builtin-exceptions › ioerror
IOError | Python’s Built-in Exceptions – Real Python
IOError is an alias for OSError, so IOError is OSError evaluates to True. Python keeps the name purely for backward compatibility, so existing code that catches IOError still works and raises no deprecation warning.
🌐
CopyProgramming
copyprogramming.com › howto › python-which-is-the-parent-ioerror-or-oserror
Python: IOError vs OSError – Complete Guide with Latest 2026 Best Practices - Python ioerror vs oserror complete guide with latest
December 30, 2025 - In Python, OSError is the parent class, and IOError is its alias or child class. Starting with Python 3.3, the Python development team consolidated these exception types to reduce confusion, making IOError a direct reference to OSError rather than a separate class.
🌐
CopyProgramming
copyprogramming.com › howto › difference-between-ioerror-and-oserror
Understanding OSError in Python: IOError vs OSError Differences and 2026 Best Practices - Understanding oserror in python ioerror vs oserror differences
February 14, 2026 - Since Python 3.3, IOError has been fully aliased to OSError, eliminating the distinction and unifying handling under one class for better code reliability. This guide covers what OSError means, key differences from the legacy IOError, and the latest Python 3.14 best practices as of 2026.
🌐
Python
peps.python.org › pep-3151
PEP 3151 – Reworking the OS and IO exception hierarchy | peps.python.org
July 21, 2010 - The same error condition (a ... called. The reason for this is that the os module exclusively raises OSError (or its subclass WindowsError) while the io module mostly raises IOError....
🌐
GitHub
github.com › ParmEd › ParmEd › issues › 531
load_file: OSError vs IOError · Issue #531 · ParmEd/ParmEd
January 11, 2016 - According to python doc IOError Raised when an I/O operation (such as a print statement, the built-in open() function or a method of a file object) fails for an I/O-related reason, e.g., “file not found” or “disk full”.
Author: ParmEd
🌐
Nim Forum
forum.nim-lang.org › t › 7133
How to differentiate different IOErrors?
November 1, 2020 - Sign up · Log in · Reset your password · Create account · Reset password · Create a new account
Find elsewhere
🌐
Initial Commit
initialcommit.com › blog › python-ioerror
IOError in Python | How to Solve with Examples - Initial Commit
The IOError is part of a larger group of built-in exceptions. This group of built-in exceptions makes up the OSError exception class and includes exceptions relating to socket errors and other I/O issues.
🌐
TutorialsPoint
tutorialspoint.com › How-to-catch-IOError-Exception-in-Python
How to catch IOError Exception in Python?
In Python 3, IOError was merged into the OSError, so you can rely on OSError alone to catch both kinds of errors, though for backward compatibility, you can still use except OSError or except (IOError, OSError).
🌐
Runebook.dev
runebook.dev › en › docs › python › library › exceptions › IOError
Python Exception Deep Dive: What to Use Instead of IOError
This means that when an I/O error happens in modern Python versions (3.3 and later), the exception raised is technically OSError, but you can still catch it using IOError for backward compatibility or clarity.
🌐
Stack Overflow
stackoverflow.com › questions › 78355889 › dealing-with-i-o-exceptions-beyond-oserror
python - Dealing with I/O exceptions beyond OSError - Stack Overflow
class Message: log_date = f"{datetime.now():%Y%m%d}" log_file = log_date + '.log' try: log = open(log_file, 'a') log.write(f"{log_file} opened\n") log.flush() except OSError as err: errno, strerror = err.args print(f"I/O Error with {log_file}; {strerror}") def print(msg: str): today = f"{datetime.now():%Y%m%d}" try: if today != Message.log_date: Message.log.close() Message.log_date = today Message.log_file = today + '.log' Message.log = open(Message.log_file, 'a') Message.log.write(f"{Message.log_file} opened\n") Message.log.write(f"{msg}\n") Message.log.flush() except OSError as err: errno, strerror = err.args print(f"I/O Error with {Message.log_file}; {strerror}")
🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 documentation
Changed in version 3.3: EnvironmentError, IOError, WindowsError, socket.error, select.error and mmap.error have been merged into OSError, and the constructor may return a subclass.
🌐
GitHub
github.com › asottile › pyupgrade › issues › 141
py3.3+: IOError (and others) -> OSError · Issue #141 · asottile/pyupgrade
May 10, 2019 - In Python 3.3+ the following exceptions are now simple aliases of OSError: IOError, EnvironmentError, WindowsError, mmap.error, socket.error and select.error. The aliases have been removed from the...
Author: asottile
🌐
Python
docs.python.org › 3.3 › library › exceptions.html
5. Built-in Exceptions — Python 3.3.7 documentation
Changed in version 3.3: EnvironmentError, IOError, WindowsError, VMSError, socket.error, select.error and mmap.error have been merged into OSError.
🌐
Python
docs.python.org › 3.2 › library › exceptions.html
5. Built-in Exceptions — Python v3.2.6 documentation
The base class for exceptions that can occur outside the Python system: IOError, OSError.
🌐
Astral
docs.astral.sh › ruff › rules › os-error-alias
os-error-alias (UP024) | Ruff - Astral Docs
In Python 3.3, a variety of other exceptions, like WindowsError were aliased to OSError. These aliases remain in place for compatibility with older versions of Python, but may be removed in future versions. Prefer using OSError directly, as it is more idiomatic and future-proof. raise IOError ·
🌐
Reddit
reddit.com › r/learnpython › what is meaning of environmenterror, ioerror?
r/learnpython on Reddit: What is meaning of EnvironmentError, IOError?
March 16, 2021 -

I was going through documentation of Python learning about Exceptions.

On this page of documentation https://docs.python.org/3/library/exceptions.html#Exception I found EnvironmentError, IOError but there is not any text defining these.

Can anybody here explain these two?

Thanks

🌐
Python Module of the Week
pymotw.com › 2 › exceptions
exceptions – Built-in error classes - Python Module of the Week
Traceback (most recent call last): ... '.do_something') NotImplementedError: BaseClass.do_something ... OSError serves as the error class for the os module, and is raised when an error comes back from an os-specific function....