python3.6利用pyinstaller打包程序为.exe

python3.6环境下直接用pip安装是用不了的,会报错,因为还没有适合python3.6的pyinstaller库。
我今天搞这个包也是碰到了很多坑,现在总算弄好了,下面给大家分享一下子。
我一般都是用pip install 库名 方式装库的,但是这样根本装不上pyinstaller,最后网上找的这种。进入cmd命令行(最好以管理员方式进吧)
输入

pip install pyinstaller -i https://pypi.douban.com/simple

是不是速度很快,噗哈哈哈哈哈。。
这下pyinstaller已经装好了
我一般用的工具是pycharm,但是在pycharm打包程序时又出错。我想打包一个名为六边形.py的文件,具体错误如下

D:\PycharmProjects\python-two>pyinstaller -F 六边形.py
122 INFO: PyInstaller: 3.4
122 INFO: Python: 3.6.5
122 INFO: Platform: Windows-10-10.0.17134-SP0
136 INFO: wrote D:\PycharmProjects\python-two\六边形.spec
138 INFO: UPX is not available.
147 INFO: Extending PYTHONPATH with paths
['D:\\PycharmProjects\\python-two', 'D:\\PycharmProjects\\python-two']
148 INFO: checking Analysis
148 INFO: Building Analysis because Analysis-00.toc is non existent
149 INFO: Initializing module dependency graph...
150 INFO: Initializing module graph hooks...
156 INFO: Analyzing base_library.zip ...
5668 INFO: running Analysis Analysis-00.toc
5673 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\tjb\appdata\local\programs\python\python36-32\python.exe
7058 INFO: Caching module hooks...
7068 INFO: Analyzing D:\PycharmProjects\python-two\六边形.py
7691 INFO: Loading module hooks...
7693 INFO: Loading module hook "hook-encodings.py"...
7997 INFO: Loading module hook "hook-pydoc.py"...
8008 INFO: Loading module hook "hook-xml.py"...
8991 INFO: Loading module hook "hook-_tkinter.py"...
9376 INFO: checking Tree
9376 INFO: Building Tree because Tree-00.toc is non existent
9376 INFO: Building Tree Tree-00.toc
9527 INFO: checking Tree
9530 INFO: Building Tree because Tree-01.toc is non existent
9530 INFO: Building Tree Tree-01.toc
9625 INFO: Looking for ctypes DLLs
9625 INFO: Analyzing run-time hooks ...
9632 INFO: Including run-time hook 'pyi_rth__tkinter.py'
9648 INFO: Looking for dynamic libraries
10142 INFO: Looking for eggs
10142 INFO: Using Python library c:\users\tjb\appdata\local\programs\python\python36-32\python36.dll
10142 INFO: Found binding redirects:
[]
10157 INFO: Warnings written to D:\PycharmProjects\python-two\build\六边形\warn-六边形.txt
10252 INFO: Graph cross-reference written to D:\PycharmProjects\python-two\build\六边形\xref-六边形.html
10437 INFO: checking PYZ
10438 INFO: Building PYZ because PYZ-00.toc is non existent
10439 INFO: Building PYZ (ZlibArchive) D:\PycharmProjects\python-two\build\六边形\PYZ-00.pyz
11602 INFO: Building PYZ (ZlibArchive) D:\PycharmProjects\python-two\build\六边形\PYZ-00.pyz completed success
fully.
Traceback (most recent call last):
  File "c:\users\tjb\appdata\local\programs\python\python36-32\lib\runpy.py", line 193, in _run_module_as_main

    "__main__", mod_spec)
  File "c:\users\tjb\appdata\local\programs\python\python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\TJB\AppData\Local\Programs\Python\Python36-32\Scripts\pyinstaller.exe\__main__.py", line 9, i
n <module>
  File "c:\users\tjb\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\__main__.py", lin
e 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\tjb\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\__main__.py", lin
e 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\tjb\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\building\build_ma
in.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\tjb\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\building\build_ma
in.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 32, in <module>
  File "c:\users\tjb\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\building\api.py",
 line 410, in __init__
    self.console, self.uac_admin, self.uac_uiaccess)
  File "c:\users\tjb\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\utils\win32\winma
nifest.py", line 1076, in create_manifest
    old_xml = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 160: illegal multibyte sequence

发现是格式错误,具体解决办法如下。
进入报错的最后一行那个.py文件下,即winmainifest.py文件,在第1076行,改成这样
在这里插入图片描述
然后再次打包,就ok了,我是在pycharm下面的终端命令行里直接打包文件。

猜你喜欢

转载自blog.csdn.net/qq_42199781/article/details/88777860