Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to view path of Python module

📅 2019-Apr-26 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ module, path, python ⬩ 📚 Archive

To view the paths of an imported Python module, say tensorflow:

import tensorflow

# Output is:
# ['/usr/local/lib/python3.6/site-packages/tensorflow/python/keras/api/_v1',
#  '/usr/local/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/api/_v1',
#  '/usr/local/lib/python3.6/site-packages/tensorflow',
#  '/usr/local/lib/python3.6/site-packages/tensorflow/_api/v1']

This can be useful to check if the right module from the right location is being imported. It is also useful to know where to go check out the Python source files of a module for inspection or debugging.

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧