← Go Back

How to Check if a Module Is Installed

In Python 3.6 and above, catch de ModuleNotFoundError exception:

try:
import win32api
except ModuleNotFoundError:
print("pywin32 is not installed.")
else:
print("pywin32 is installed!")

Prior to Python 3.6, use ImportError:

try:
import win32api
except ImportError:
print("pywin32 is not installed.")
else:
print("pywin32 is installed!")

If you need to support both Python >= 3.6 and < 3.6, just use ImportError.

modules


🐍 You might also find interesting: