check if module is installed python code example

Example 1: how to find where python modules are installed

# this will show where numpy is installed
pip show numpy

Example 2: bash check if python package is installed

$ python2 -m doesnt_exist |& grep -q 'No module named' && echo 'Nope' || echo 'Yup'
Nope

$ python2 -m math |& grep -q 'No module named' && echo 'Nope' || echo 'Yup'
Yup

Example 3: module installed but not found python

>/bin/env python -m pip install --upgrade mymodule
# or 
/bin/env python -m pip install --upgrade mymodule

Tags:

Misc Example