如何获取python模块的路径(不是sys.executable) [英] How to get path of a python module ( not sys.executable )

查看:124
本文介绍了如何获取python模块的路径(不是sys.executable)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在python程序中获取PyQt库的路径.程序作为脚本从其他应用程序运行,因此我的

I need to get Path for PyQt library in python program. Program is run as a script from another application, therefore my

sys.executable = 'D:/program files/visum/exe/visum115.exe

并且我需要我的实际python路径(以及PyQt库模块的路径)

and I need my actual python path (and path for PyQt library module)

Path = C:\Python25\Lib\site-packages\PyQt4\plugins

我正在尝试

os.environ['PYTHONPATH']

但是我不确定它是否可靠.

but I'm not sure if it can be robust.

致谢!

PS.我需要它才能插入插件:

PS. I need it to be able to plug plugins:

qApp.addLibaryPath('C:\Python25\Lib\site-packages\PyQt4\plugins')

推荐答案

您可以尝试加载该模块,并在检查其 __ file __ 属性后获取.pyc文件的路径.

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

例如这样的

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

关于, HTH!

这篇关于如何获取python模块的路径(不是sys.executable)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆