How to view path of Python module

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

import tensorflow
print(tensorflow.__path__)

# 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.