0

I want to create .exe of my python code which contains tkinter GUI. I tried pyinstaller file.py -w -F but then the file doesn't work. The file works fine if I use only one of the flags but not with both.

This is the code

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()

And these are pyinstaller outputs

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.

I have added pywin32 and pypiwin32 both still it isn't resolving ModuleNotFoundError

Vibhakar
  • 1
  • 3
  • "Not working" is not enough. Also using window mode and one file doesn't conflict. So please add your minimal working code and give us the exact problem so we can help you figure it out. – Masoud Rahimi Jun 11 '19 at 03:45
  • Using both the modes indeed creates a .exe file but it doesn't open. I have checked the task manager it exists as a task there but does appear on the screen ( Its a GUI program) – Vibhakar Jun 18 '19 at 11:10
  • It is because you have errors and as there is no console you can't see that. And as we don't know your code and error we can't guess. So as I said give us a minimal example of your code or redirect [stdout to a file](https://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python). – Masoud Rahimi Jun 18 '19 at 13:09
  • I have edited the questions with code. Please help – Vibhakar Jun 19 '19 at 09:53
  • I tested your app and it worked without any problem. Your code is OK and you don't need to do anything. Try using a [virtualenv](https://docs.python-guide.org/dev/virtualenvs/#lower-level-virtualenv) and repeat the whole process again. – Masoud Rahimi Jun 19 '19 at 12:47
  • Thanks. But the problem persists even with virtualenv – Vibhakar Jun 19 '19 at 17:38
  • Put all your code in a try/except block and redirect exceptions to a file. If there is any error you would find that. – Masoud Rahimi Jun 19 '19 at 18:57
  • Modified the code as you said to write errors to a file but it is not creating any file upon running – Vibhakar Jun 20 '19 at 16:21

0 Answers0