使用Pyinstaller打包python py文件注意事项

首先需要将cmd或者PowerShell目录cd 跳转到py脚本所在目录,然后直接执行 Pyinstaller -F即可完成程序的打包,其中我们关心它有哪些常见参数:

      输入参数的含义

  • -F 表示生成单个可执行文件

  • -w 表示去掉控制台窗口,这在GUI界面时非常有用。不过如果是命令行程序的话那就把这个选项删除吧!

  • -p 表示你自己自定义需要加载的类路径,一般情况下用不到

  • -i 表示可执行文件的图标

  • 不过顺序上有要求,如果想要修改默认图标,正确的写法是:Pyinstaller -F -w -i "ico文件完整路径" "py文件完整路径”,否则经常编译出错。
  • 如果编译报"UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 5650: invalid start byte",可尝试在powershell下输入:chcp 65001
  • 常见报错如下:
  • 171 INFO: checking Analysis
    171 INFO: Building Analysis because out00-Analysis.toc is non existent
    171 INFO: Initializing module dependency graph...
    187 INFO: Initializing module graph hooks...
    187 INFO: Analyzing base_library.zip ...
    5538 INFO: running Analysis out00-Analysis.toc
    5553 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
      required by d:\program files\python35\python.exe
    6380 INFO: Caching module hooks...
    6380 INFO: Analyzing D:\photo.ico
    Traceback (most recent call last):
      File "D:\Program Files\python35\Scripts\pyinstaller-script.py", line 11, in <module>
        load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')()
      File "d:\program files\python35\lib\site-packages\PyInstaller\__main__.py", line 94, in run
        run_build(pyi_config, spec_file, **vars(args))
      File "d:\program files\python35\lib\site-packages\PyInstaller\__main__.py", line 46, in run_bu
        PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
      File "d:\program files\python35\lib\site-packages\PyInstaller\building\build_main.py", line 79
        build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
      File "d:\program files\python35\lib\site-packages\PyInstaller\building\build_main.py", line 73
        exec(text, spec_namespace)
      File "<string>", line 16, in <module>
      File "d:\program files\python35\lib\site-packages\PyInstaller\building\build_main.py", line 21
        self.__postinit__()
      File "d:\program files\python35\lib\site-packages\PyInstaller\building\datastruct.py", line 16
        self.assemble()
      File "d:\program files\python35\lib\site-packages\PyInstaller\building\build_main.py", line 41
        priority_scripts.append(self.graph.run_script(script))
      File "d:\program files\python35\lib\site-packages\PyInstaller\depend\analysis.py", line 201, i
        self._top_script_node = super(PyiModuleGraph, self).run_script(pathname)
      File "d:\program files\python35\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py",
    t
        contents = fp.read() + '\n'
      File "d:\program files\python35\lib\codecs.py", line 321, in decode
        (result, consumed) = self._buffer_decode(data, self.errors, final)
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 5650: invalid start byte

 快来扫码关注我的公众号 获取更多爬虫、数据分析的知识!

posted @ 2018-06-14 09:04  NewJune  阅读(1472)  评论(0编辑  收藏  举报