【问题标题】:How check application verision information in PySide如何在 PySide 中查看应用程序版本信息
【发布时间】:2015-09-16 00:28:26
【问题描述】:

我使用Python (PySide) + PyInstaller 创建了 EXE 文件。一旦我尝试使用

打印 QtGui.QApplication.applicationVersion()

我没有看到应用程序的 x.x.x.x 格式的有效版本。

PySide 中是否有任何内置函数而不是这个,或者我应该使用其他库来代替它吗?

PS。我不相信 Python 没有任何方法可以提取有关 EXE 的信息 :)

【问题讨论】:

标签: python windows python-2.7 build pyinstaller


【解决方案1】:

看看here

这里有你要找的一切!

希望这会有所帮助。

【讨论】:

  • 谢谢,但是这个链接显示了我们如何提取 PySide 框架的版本。我正在寻找关于已编译应用程序的版本
  • 你要的不是 QtCore 版本吗?
  • 不,我正在寻找关于已编译应用程序的版本
【解决方案2】:

找到了一种方法:

import win32api    

def get_version_info():
    try:
        filename = APP_FILENAME
        return get_file_properties(filename)['FileVersion']
    except BaseException, err:
        log_error(err.message)
        return '0.0.0.0'

def get_file_properties(filename):
    """
    Read all properties of the given file return them as a dictionary.
    """
    propNames = ('Comments', 'InternalName', 'ProductName',
        'CompanyName', 'LegalCopyright', 'ProductVersion',
        'FileDescription', 'LegalTrademarks', 'PrivateBuild',
        'FileVersion', 'OriginalFilename', 'SpecialBuild')

    props = {'FixedFileInfo': None, 'StringFileInfo': None, 'FileVersion': '0.0.0.0'}

    try:
        # backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
        print filename
        fixedInfo = win32api.GetFileVersionInfo(filename, '\\')
        props['FixedFileInfo'] = fixedInfo
        props['FileVersion'] = "%d.%d.%d.%d" % (fixedInfo['FileVersionMS'] / 65536,
                fixedInfo['FileVersionMS'] % 65536, fixedInfo['FileVersionLS'] / 65536,
                fixedInfo['FileVersionLS'] % 65536)

        # \VarFileInfo\Translation returns list of available (language, codepage)
        # pairs that can be used to retreive string info. We are using only the first pair.
        lang, codepage = win32api.GetFileVersionInfo(filename, '\\VarFileInfo\\Translation')[0]

        # any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
        # two are language/codepage pair returned from above

        strInfo = {}
        for propName in propNames:
            strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage, propName)
            ## print str_info
            strInfo[propName] = win32api.GetFileVersionInfo(filename, strInfoPath)

        props['StringFileInfo'] = strInfo
    except BaseException, err:
        log_error(err.message)
    return props

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2019-10-15
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    相关资源
    最近更新 更多