How to get path of a python module ( not sys.executable )

ε祈祈猫儿з 提交于 2019-12-04 03:45:25

you can try to load the module and after check for it's __file__ attribute to get the path of the .pyc file.

for example like this:

import MODULE, os
path = os.path.dirname(MODULE.__file__)

Regards, HTH!

What you're looking for is sys.path:

>>> import sys
>>> sys.path
 ['',
 '/usr/lib/python2.7/site-packages/virtualenvwrapper.github-0.1-py2.7.egg',
 '/usr/lib/python2.7/site-packages/pycharm-debug.egg',
 '/usr/lib/python2.7/site-packages/Fom-0.9.2-py2.7.egg',
 '/usr/lib/python2.7/site-packages/blinker-1.1-py2.7.egg',
 '/usr/lib/python2.7/site-packages/httplib2-0.6.0-py2.7.egg',
 '/usr/lib/python27.zip',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7/site-packages',
 '/usr/lib/python2.7/site-packages/Numeric',
 '/usr/lib/python2.7/site-packages/PIL',
 '/usr/lib/python2.7/site-packages/gst-0.10',
 '/usr/lib/python2.7/site-packages/gtk-2.0',
 '/usr/lib/python2.7/site-packages/setuptools-0.6c11.egg-info',
 '/usr/lib/python2.7/site-packages/wx-2.8-gtk2-unicode']
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!