python - 如何获取 python 模块的路径(不是 sys.executable )

标签 python path pyqt qwebkit

我需要在 python 程序中获取 PyQt 库的路径。程序作为来自另一个应用程序的脚本运行,因此我的

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

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

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

我正在尝试

os.environ['PYTHONPATH']

但我不确定它是否可以健壮。

问候!

附言。我需要它才能插入插件:

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

最佳答案

您可以尝试加载模块并在检查它的 __file__ 属性后获取 .pyc 文件的路径。

例如像这样:

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

问候, HTH!

关于python - 如何获取 python 模块的路径(不是 sys.executable ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5003226/

相关文章:

python - pyqt:如何让QLabel占据整个窗口

python - 仅使用一次 glob 搜索多个模式

python - 如何在Python中的数据框中将日期时间舍入为十分钟日期时间

java - 无法从资源文件夹中读取文件

git - git如何决定在git-svn中使用哪个版本的svn?

python - FFmpeg 在 Path 中,但在 CMD 中运行导致 "FFmpeg not recognized as internal or external command"

python - PyQt、SQLAlchemy - 哪些 session 适合?

python - 如何重启 PyQt5 应用程序

python - 如何将特定html标签中的数据转换为字典

python - 如何在 Pycharm 的调试 session 中断期间向 python 类/对象添加方法?