python check if package is installed command line code example
Example 1: check package version python
import packagename
print(packagename.__version__)
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