美文网首页
[Python]通过Pyinstaller库打包我的一个IP地址

[Python]通过Pyinstaller库打包我的一个IP地址

作者: 胜言_ | 来源:发表于2018-06-23 12:43 被阅读68次

    1. 安装pyinstaller库

    python -m pip install pyinstaller
    

    2. 打包ip.py文件

    C:\Users\ws\Desktop\crawler\temp > pyinstaller -F -c --icon=my.ico ip.py
    62 INFO: PyInstaller: 3.3.1
    62 INFO: Python: 3.6.5
    62 INFO: Platform: Windows-10-10.0.16299-SP0
    ......
    9148 INFO: Appending archive to EXE   
    C:\Users\ws\Desktop\crawler\temp\dist\ip.exe
    9148 INFO: Building EXE from out00-EXE.toc completed successfully.
    

    我这里要打包的文件是C:\Users\ws\Desktop\crawler\temp\ip.py, 文件图标名为my.ico, 在控制台运行(没做GUI)
    pyinstaller里的主要参数
    -icon=图标路径
    -F 打包成一个exe文件
    -w 使用窗口,无控制台(有GUI的程序要用到)
    -c 使用控制台,无窗口
    -D 创建一个目录,里面包含exe以及其他一些依赖性文件
    –version-file file_version_info.txt :表示将标准版本信息文件的内容赋给exe文件的属性
    更多请键入 pyinstaller -h 来查看参数

    输出结果

    dist目录下是exe文件,可单独执行。


    3. (可选)打包程序时键入版本信息


    • 在ip.py所在目录下按以上示例创建一个版本信息文件:file_version_info.txt 文本文件。
      我这里给出 file_version_info.txt 的具体格式示例。
    # UTF-8
    #
    # For more details about fixed file info 'ffi' see:
    # http://msdn.microsoft.com/en-us/library/ms646997.aspx
    VSVersionInfo(
      ffi=FixedFileInfo(
        # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
        # Set not needed items to zero 0.
        filevers=(0, 1, 0, 0),
        prodvers=(1, 1, 0, 0),
        # Contains a bitmask that specifies the valid bits 'flags'r
        mask=0x3f,
        # Contains a bitmask that specifies the Boolean attributes of the file.
        flags=0x28,
        # The operating system for which this file was designed.
        # 0x4 - NT and there is no need to change it.
        OS=0x40004,
        # The general type of file.
        # 0x1 - the file is an application.
        fileType=0x2,
        # The function of the file.
        # 0x0 - the function is not defined for this fileType
        subtype=0x0,
        # Creation date and time stamp.
        date=(0, 0)
        ),
      kids=[
        StringFileInfo(
          [
          StringTable(
            u'000004b0',
            [StringStruct(u'FileVersion', u'0.1.0.0'),
            StringStruct(u'ProductVersion', u'1.1.0.0'),
            StringStruct(u'OriginalFilename', u'ip'),
            StringStruct(u'InternalName', u'ip'),
            StringStruct(u'FileDescription', u'<无>'),
            StringStruct(u'CompanyName', u'<小白王_960064995>'),
            StringStruct(u'LegalCopyright', u'©小白王_960064995'),
            StringStruct(u'ProductName', u'ip'),
            StringStruct(u'Comments', u'<IP地址查询>'),
            StringStruct(u'LegalTrademarks', u' '),
            StringStruct(u'e', u''),
            StringStruct(u'ld', u' '),
            StringStruct(u'i', u''),
            StringStruct(u'ld', u'D')])
          ]), 
        VarFileInfo([VarStruct(u'Translation', [0, 1200])])
      ]
    )
    
    • 打开系统cmd键入:pyinstaller -F -c --icon=my.ico --version-file file_version_info.txt ip.py (注意:重新打包!,示例)
    C:\Users\ws\Desktop\crawler\temp>pyinstaller -F -c --icon=my.ico --version-file file_version_info.txt ip.py
    62 INFO: PyInstaller: 3.3.1
    62 INFO: Python: 3.6.5
    62 INFO: Platform: Windows-10-10.0.16299-SP0
    62 INFO: wrote C:\Users\ws\Desktop\crawler\temp\ip.spec
    62 INFO: UPX is not available.
    78 INFO: Extending PYTHONPATH with paths
    ['C:\\Users\\ws\\Desktop\\crawler\\temp',
     'C:\\Users\\ws\\Desktop\\crawler\\temp']
    78 INFO: checking Analysis
    78 INFO: Building Analysis because out00-Analysis.toc is non existent
    78 INFO: Initializing module dependency graph...
    78 INFO: Initializing module graph hooks...
    78 INFO: Analyzing base_library.zip ...
    ......
    9146 INFO: Writing RT_ICON 1 resource with 4264 bytes
    9177 INFO: Appending archive to EXE C:\Users\ws\Desktop\crawler\temp\dist\ip.exe
    9177 INFO: Building EXE from out00-EXE.toc completed successfully.
    
    • 成功!


      对比
      Running ip.exe
    我的公众号,一起进步吧!

    相关文章

      网友评论

          本文标题:[Python]通过Pyinstaller库打包我的一个IP地址

          本文链接:https://www.haomeiwen.com/subject/jkpryftx.html