簡體   English   中英

PyInstaller 未創建 .exe 文件

[英]PyInstaller is not creating an .exe file

我正在嘗試使用 PyInstaller 和我的腳本創建一個可執行文件。 作為參考,我使用的是帶有 Python 3.8.0 和 PyInstaller 3.5 版的 Windows 10。

我的腳本名為 hello_world.py,它保存在它自己的文件夾中。

print("Hello World!")

在命令提示符中,我導航到 hello_world.py 所在的文件夾並運行:

pyinstaller hello_world.py

這是輸出:

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)

這將創建名為“dist”和“build”的文件夾以及名為“hello_world.spec”的文件,但“dist”文件夾為空。 出了什么問題?

我搜索

類型錯誤:需要一個整數(得到類型字節)

你讀過這個嗎?

我過去遇到過這個問題,請您執行以下操作:打開 Anaconda 提示符或每個示例 spyder 或 Atom 終端的任何其他 IDE,以管理員身份在命令行中導航到 .py 所在的文件夾並按如下方式運行命令:

在我的示例中,我要編譯的文件是 getwindowsversion.py

這將創建可以使用的獨立 .exe,

pyinstaller --onefile getwindowsversion.py

如果你想創建常規構建,

pyinstaller getwindowsversion.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM