简体   繁体   English

PyInstaller 未创建 .exe 文件

[英]PyInstaller is not creating an .exe file

I'm trying to create an executable file using PyInstaller with my script.我正在尝试使用 PyInstaller 和我的脚本创建一个可执行文件。 For reference, I am using Windows 10 with Python 3.8.0 and PyInstaller version 3.5.作为参考,我使用的是带有 Python 3.8.0 和 PyInstaller 3.5 版的 Windows 10。

My script is called hello_world.py and it is saved in it's own folder.我的脚本名为 hello_world.py,它保存在它自己的文件夹中。

print("Hello World!")

In command prompt, I navigate to the folder that hello_world.py is in and run:在命令提示符中,我导航到 hello_world.py 所在的文件夹并运行:

pyinstaller hello_world.py

And this is the output:这是输出:

46 INFO: PyInstaller: 3.5
46 INFO: Python: 3.8.0
46 INFO: Platform: Windows-10-10.0.17763-SP0
62 INFO: wrote F:\Python\Python Scripts\Pyinstaller\Py installer test\hello_world.spec
78 INFO: UPX is not available.
78 INFO: Extending PYTHONPATH with paths
['F:\\Python\\Python Scripts\\Pyinstaller\\Py installer test',
 'F:\\Python\\Python Scripts\\Pyinstaller\\Py installer test']
78 INFO: checking Analysis
78 INFO: Building Analysis because Analysis-00.toc is non existent
78 INFO: Initializing module dependency graph...
93 INFO: Initializing module graph hooks...
93 INFO: Analyzing base_library.zip ...
3592 INFO: running Analysis Analysis-00.toc
3592 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\l&a\appdata\local\programs\python\python38\python.exe
4014 INFO: Caching module hooks...
4014 INFO: Analyzing F:\Python\Python Scripts\Pyinstaller\Py installer test\hello_world.py
4045 INFO: Loading module hooks...
4045 INFO: Loading module hook "hook-encodings.py"...
4202 INFO: Loading module hook "hook-pydoc.py"...
4202 INFO: Loading module hook "hook-xml.py"...
4405 INFO: Looking for ctypes DLLs
4420 INFO: Analyzing run-time hooks ...
4420 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
4420 INFO: Looking for dynamic libraries
5592 INFO: Looking for eggs
5592 INFO: Using Python library c:\users\l&a\appdata\local\programs\python\python38\python38.dll
5592 INFO: Found binding redirects:
[]
5592 INFO: Warnings written to F:\Python\Python Scripts\Pyinstaller\Py installer test\build\hello_world\warn-hello_world.txt
5670 INFO: Graph cross-reference written to F:\Python\Python Scripts\Pyinstaller\Py installer test\build\hello_world\xref-hello_world.html
5686 INFO: checking PYZ
5686 INFO: Building PYZ because PYZ-00.toc is non existent
5686 INFO: Building PYZ (ZlibArchive) F:\Python\Python Scripts\Pyinstaller\Py installer test\build\hello_world\PYZ-00.pyz
Traceback (most recent call last):
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\L&A\AppData\Local\Programs\Python\Python38\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 844, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
    exec(code, spec_namespace)
  File "F:\Python\Python Scripts\Pyinstaller\Py installer test\hello_world.spec", line 18, in <module>
    pyz = PYZ(a.pure, a.zipped_data,
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\api.py", line 98, in __init__
    self.__postinit__()
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\api.py", line 128, in assemble
    self.code_dict = {
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\api.py", line 129, in <dictcomp>
    key: strip_paths_in_code(code)
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\utils.py", line 652, in strip_paths_in_code
    consts = tuple(
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\utils.py", line 653, in <genexpr>
    strip_paths_in_code(const_co, new_filename)
  File "c:\users\l&a\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\utils.py", line 660, in strip_paths_in_code
    return code_func(co.co_argcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize,
TypeError: an integer is required (got type bytes)

This creates folders called 'dist' and 'build' and a file called 'hello_world.spec' but the 'dist' folder is empty.这将创建名为“dist”和“build”的文件夹以及名为“hello_world.spec”的文件,但“dist”文件夹为空。 What is going wrong?出了什么问题?

I search for我搜索

TypeError: an integer is required (got type bytes)类型错误:需要一个整数(得到类型字节)

Did you read this?你读过这个吗?

I had this issue in the past, can you please perform the follwing: open Anaconda prompt or any other IDE per example spyder or Atom terminal, command line as admin and Navigate to the folder where the .py located and run the command as bellow:我过去遇到过这个问题,请您执行以下操作:打开 Anaconda 提示符或每个示例 spyder 或 Atom 终端的任何其他 IDE,以管理员身份在命令行中导航到 .py 所在的文件夹并按如下方式运行命令:

In my example the file I want to compile it is getwindowsversion.py在我的示例中,我要编译的文件是 getwindowsversion.py

this is will create just standalone .exe can be used,这将创建可以使用的独立 .exe,

pyinstaller --onefile getwindowsversion.py

if you want to create regular build,如果你想创建常规构建,

pyinstaller getwindowsversion.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM