Friday, June 06, 2014

Python 3.4: Check if module installed

To check whether a given module is install in Python 3.4, we can use PathFinder.find_spec class method. For example, to check if pyperclip moduel is installed / available we can use the following code:
from importlib.machinery import PathFinder
if PathFinder.find_spec('pyperclip'):
print('pyperclip module found')
else:
print('pyperclip module not found')
view raw example.py hosted with ❤ by GitHub