将Python文件转换为可执行文件

时间:2019-03-24 16:21:50

标签: python python-3.x windows pyinstaller py2exe

Python:3.6.5

PyInstaller:3.4

我在使用PyInstaller,Py2Exe和Auto-Py-To-Exe将项目转换为可执行文件时遇到问题。 我只想要一个文件。我的exe文件中需要我的资产文件夹。 Auto Py To Exe生成的命令是:

pyinstaller -y -F -w -i "D:/Eigene Dateien/Documents/Coding/Python/hangman/icon.ico" --add-data "D:/Eigene Dateien/Documents/Coding/Python/hangman/assets/images";"images/" --add-data "D:/Eigene Dateien/Documents/Coding/Python/hangman/assets/sounds";"sounds/" --add-data "D:/Eigene Dateien/Documents/Coding/Python/hangman/assets/words.txt";"." "D:/Eigene Dateien/Documents/Coding/Python/hangman/main.py"

如果我在PowerShell中使用它,则会显示:

In Zeile:1 Zeichen:175
+ ... nts/Coding/Python/hangman/assets/images";"images/" --add-data "D:/Eig ...
+                                                          ~~~~~~~~
Unerwartetes Token "add-data" in Ausdruck oder Anweisung.
In Zeile:1 Zeichen:262
+ ... nts/Coding/Python/hangman/assets/sounds";"sounds/" --add-data "D:/Eig ...
+                                                          ~~~~~~~~
Unerwartetes Token "add-data" in Ausdruck oder Anweisung.
In Zeile:1 Zeichen:344
+ ... ds.txt";"." "D:/Eigene Dateien/Documents/Coding/Python/hangman/main.p ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unerwartetes Token ""D:/Eigene Dateien/Documents/Coding/Python/hangman/main.py"" in Ausdruck oder Anweisung.
In Zeile:1 Zeichen:163
+ ... eien/Documents/Coding/Python/hangman/assets/images";"images/" --add-d ...
+                                                         ~~~~~~~~~
Der Operator "--" kann nur für Variablen oder Eigenschaften verwendet werden.
In Zeile:1 Zeichen:250
+ ... eien/Documents/Coding/Python/hangman/assets/sounds";"sounds/" --add-d ...
+                                                         ~~~~~~~~~
Der Operator "--" kann nur für Variablen oder Eigenschaften verwendet werden.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

对不起,有些文字是德语:/

D:\Eigene Dateien\Documents\Coding\Python\hangman>pyinstaller -y -F -w -i "D:/Eigene Dateien/Documents/Coding/Python/hangman/icon.ico" --add-data "D:/Eigene Dateien/Documents/Coding/Python/hangman/assets/images";"images/" --add-data "D:/Eigene Dateien/Documents/Coding
/Python/hangman/assets/sounds";"sounds/" --add-data "D:/Eigene Dateien/Documents/Coding/Python/hangman/assets/words.txt";"." "D:/Eigene Dateien/Documents/Coding/Python/hangman/main.py"
75 INFO: PyInstaller: 3.4
75 INFO: Python: 3.6.5
76 INFO: Platform: Windows-10-10.0.17134-SP0
77 INFO: wrote D:\Eigene Dateien\Documents\Coding\Python\hangman\main.spec
80 INFO: UPX is not available.
82 INFO: Extending PYTHONPATH with paths
['D:\\Eigene Dateien\\Documents\\Coding\\Python\\hangman',
 'D:\\Eigene Dateien\\Documents\\Coding\\Python\\hangman']
82 INFO: checking Analysis
146 INFO: Appending 'datas' from .spec
151 INFO: checking PYZ
187 INFO: checking PKG
189 INFO: Building because toc changed
189 INFO: Building PKG (CArchive) PKG-00.pkg
410 WARNING: One binary added with two internal names.
410 WARNING: ('libGLESv2.dll',
 'C:\\users\\meiss\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
 'BINARY')
410 WARNING: was placed previously at
411 WARNING: ('PyQt5\\Qt\\bin\\libGLESv2.dll',
 'C:\\users\\meiss\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
 'BINARY')
13466 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
13476 INFO: Bootloader c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe
13476 INFO: checking EXE
13478 INFO: Building because console changed
13478 INFO: Building EXE from EXE-00.toc
13483 INFO: SRCPATH [('D:\\Eigene Dateien\\Documents\\Coding\\Python\\hangman\\icon.ico', None)]
13483 INFO: Updating icons from ['D:\\Eigene Dateien\\Documents\\Coding\\Python\\hangman\\icon.ico'] to C:\Users\meiss\AppData\Local\Temp\tmpiwaatz96
Traceback (most recent call last):
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\meiss\AppData\Local\Programs\Python\Python36-32\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 32, in <module>
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\building\api.py", line 433, in __init__
    self.__postinit__()
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\building\api.py", line 522, in assemble
    icon.CopyIcons(tmpnm, self.icon)
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\utils\win32\icon.py", line 177, in CopyIcons
    return CopyIcons_FromIco(dstpath, [srcpath])
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\utils\win32\icon.py", line 134, in CopyIcons_FromIco
    for i, f in enumerate(icons):
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\utils\win32\icon.py", line 104, in __init__
    entry.fromfile(file)
  File "c:\users\meiss\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\utils\win32\icon.py", line 65, in fromfile
    self._fields_ = list(struct.unpack(self._format_, data))
struct.error: unpack requires a buffer of 16 bytes

这是IntelliJ(英语)中的输出

1 个答案:

答案 0 :(得分:0)

通过将Pyinstaller降级到3.1版,我有些运气。 pip install pyinstaller==3.1