Pyinstaller .exe无法同时创建onefile和noconsole

时间:2019-06-10 19:29:39

标签: python pyinstaller

我想创建包含tkinter GUI的python代码的.exe。我尝试了pyinstaller file.py -w -F,但是该文件不起作用。如果我仅使用其中一个标志,而不同时使用两个标志,则文件运行正常。

这是代码

import tkinter as tk
import openpyxl
import sys

def toexcel(name, age, dept):
    wb = openpyxl.Workbook()
    ws = wb.active
    age = int(age)
    if dept == 1:
        deptName = 'HR'
    else:
        deptName = 'IT'
    ws.cell(row = 1, column=1).value = name
    ws.cell(row=1, column=2).value = age
    ws.cell(row=1, column=3).value = deptName
    wb.save('UserFormData.xlsx')
    return True

def submit_details():
    name = e1.get()
    age = e2.get()
    dept = radio.get()
    if toexcel(name, age, dept):
        sys.exit()




root = tk.Tk()
radio = tk.IntVar()
frame = tk.Frame(root)
nameLabel = tk.Label(frame, text = 'Name', pady=20)
ageLabel = tk.Label(frame, text = 'Age', pady=20)
deptLabel = tk.Label(frame, text = 'Department', pady=20)
hrRadio = tk.Radiobutton(frame, text = 'HR', pady=20, variable = radio, value =1)
itRadio = tk.Radiobutton(frame, text = 'IT', pady=20, variable = radio, value =2)
submit = tk.Button(root, text = 'SUBMIT', width = 20, command = submit_details)

nameLabel.grid(row=0)
ageLabel.grid(row=1)
deptLabel.grid(row=2)
#submit.grid(row=4)


e1 = tk.Entry(frame)
e2 = tk.Entry(frame)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
hrRadio.grid(row=2, column=1)
itRadio.grid(row=2, column=2)

frame.pack(padx =20)
submit.pack(pady=20)
root.mainloop()

这些是pyinstaller输出

C:\Users\asus\Desktop\HMC\Form>pyinstaller --onefile --noconsole user_form.py
61 INFO: PyInstaller: 3.4
62 INFO: Python: 3.7.3
62 INFO: Platform: Windows-10-10.0.17134-SP0
63 INFO: wrote C:\Users\asus\Desktop\HMC\Form\user_form.spec
64 INFO: UPX is not available.
66 INFO: Extending PYTHONPATH with paths
['C:\\Users\\asus\\Desktop\\HMC\\Form', 'C:\\Users\\asus\\Desktop\\HMC\\Form']
67 INFO: checking Analysis
67 INFO: Building Analysis because Analysis-00.toc is non existent
67 INFO: Initializing module dependency graph...
69 INFO: Initializing module graph hooks...
71 INFO: Analyzing base_library.zip ...
3531 INFO: running Analysis Analysis-00.toc
3533 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\python37\python.exe
3843 INFO: Caching module hooks...
3849 INFO: Analyzing C:\Users\asus\Desktop\HMC\Form\user_form.py
4625 INFO: Processing pre-find module path hook   distutils
5546 INFO: Processing pre-find module path hook   site
5546 INFO: site: retargeting to fake-dir 'c:\\python37\\lib\\site-packages\\PyInstaller\\fake-modules'
6948 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
9561 INFO: Processing pre-safe import module hook   six.moves
14990 INFO: Loading module hooks...
14990 INFO: Loading module hook "hook-distutils.py"...
14992 INFO: Loading module hook "hook-encodings.py"...
15077 INFO: Loading module hook "hook-lib2to3.py"...
15081 INFO: Loading module hook "hook-numpy.core.py"...
15159 INFO: Loading module hook "hook-numpy.py"...
15160 INFO: Loading module hook "hook-openpyxl.py"...
15168 INFO: Loading module hook "hook-pandas.py"...
16166 INFO: Loading module hook "hook-pkg_resources.py"...
16510 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
16560 INFO: Processing pre-safe import module hook   win32com
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
16727 INFO: Loading module hook "hook-pydoc.py"...
16728 INFO: Loading module hook "hook-PyQt5.py"...
16853 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
17169 INFO: Loading module hook "hook-pytz.py"...
17257 INFO: Loading module hook "hook-setuptools.py"...
17780 INFO: Loading module hook "hook-sqlite3.py"...
17867 INFO: Loading module hook "hook-sysconfig.py"...
17868 INFO: Loading module hook "hook-xml.dom.domreg.py"...
17869 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
17870 INFO: Loading module hook "hook-xml.py"...
17870 INFO: Loading module hook "hook-_tkinter.py"...
18011 INFO: checking Tree
18011 INFO: Building Tree because Tree-00.toc is non existent
18013 INFO: Building Tree Tree-00.toc
18071 INFO: checking Tree
18072 INFO: Building Tree because Tree-01.toc is non existent
18074 INFO: Building Tree Tree-01.toc
18085 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
18178 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
18380 INFO: Looking for ctypes DLLs
18430 WARNING: library user32 required via ctypes not found
18456 INFO: Analyzing run-time hooks ...
18465 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
18468 INFO: Including run-time hook 'pyi_rth_pkgres.py'
18469 INFO: Including run-time hook 'pyi_rth_qt5.py'
18471 INFO: Including run-time hook 'pyi_rth__tkinter.py'
18494 INFO: Looking for dynamic libraries
19686 INFO: Looking for eggs
19686 INFO: Using Python library c:\python37\python37.dll
19688 INFO: Found binding redirects:
[]
19709 INFO: Warnings written to C:\Users\asus\Desktop\HMC\Form\build\user_form\warn-user_form.txt
19896 INFO: Graph cross-reference written to C:\Users\asus\Desktop\HMC\Form\build\user_form\xref-user_form.html
19957 INFO: checking PYZ
19957 INFO: Building PYZ because PYZ-00.toc is non existent
19958 INFO: Building PYZ (ZlibArchive) C:\Users\asus\Desktop\HMC\Form\build\user_form\PYZ-00.pyz
21739 INFO: Building PYZ (ZlibArchive) C:\Users\asus\Desktop\HMC\Form\build\user_form\PYZ-00.pyz completed successfully.
21772 INFO: checking PKG
21773 INFO: Building PKG because PKG-00.toc is non existent
21775 INFO: Building PKG (CArchive) PKG-00.pkg
22246 WARNING: One binary added with two internal names.
22246 WARNING: ('libGLESv2.dll',
 'C:\\python37\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
 'BINARY')
22248 WARNING: was placed previously at
22248 WARNING: ('PyQt5\\Qt\\bin\\libGLESv2.dll',
 'C:\\python37\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
 'BINARY')
41906 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
41944 INFO: Bootloader c:\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
41945 INFO: checking EXE
41945 INFO: Building EXE because EXE-00.toc is non existent
41945 INFO: Building EXE from EXE-00.toc
41945 INFO: Appending archive to EXE C:\Users\asus\Desktop\HMC\Form\dist\user_form.exe
41996 INFO: Building EXE from EXE-00.toc completed successfully.

我已经添加了pywin32和pypiwin32,但仍无法解决ModuleNotFoundError

0 个答案:

没有答案