How can I generate the exe application from python file [duplicate] - python

This question already has answers here:
How to install python application with tkcalendar module by pyinstaller?
(3 answers)
Closed 3 years ago.
I'm trying to get the .exe file from this script using pyinstaller
I used this command pyinstaller -w -F test.py while I'm in the test directory
the file test.py contains
from tkinter import *
from tkcalendar import DateEntry
root = Tk()
date = DateEntry(root, year=2001, month=11, day=11, width=17,)
date.pack()
root.mainloop()
The .exe file that I get is not WORKING?
when I do this pyinstaller -F test.py I get the error of no module named babel.numbers on the console

It seems that PyInstaller can't resolve module babel.numbers for tkcalendar. One easy way is to use hidden-import:
pyinstaller -F --hidden-import "babel.numbers" test.py

Related

how to add lzw_decode from imagecodecs at pyinstaller?

I need to transfer my main.py file to .exe and I made that
pyinstaller -F --hidden-import="sklearn.utils._cython_blas" --hidden-import="sklearn.neighbors.typedefs" --hidden-import="sklearn.neighbors.quad_tree" --hidden-import="sklearn.tree._utils" main.py
but I got this Error could not import the name 'lzw_decode' from 'imagecodecs'

PyInstaller + tkdnd/tkinterdnd2 "Unable to load tkdnd library" when launching frozen exe. Works when launched from script

In my script I am using tkinterdnd2 library to achieve drag and drop functionality from Windows explorer into my tkinter UI.
from tkinterdnd2 import TkinterDnD, DND_FILES
import tkinter as tk
class TkWindow:
def __init__(self):
self.window = TkinterDnD.Tk()
self.tbox = tk.Listbox(self.window)
self.tbox.pack(fill=tk.BOTH)
self.tbox.drop_target_register(DND_FILES)
self.tbox.dnd_bind('<<Drop>>', self.tk_files_dropped)
self.window.mainloop()
def tk_files_dropped(self, event):
messagebox.showinfo("x", event.data)
TkWindow()
When I launch the script - everything works.
But when I freeze the project to a single EXE with PyInstaller, and run it, I get this error:
I tried this solutions already:
I added the pyinstaller-hook as instructed in the tkinterdnd2 repository:
from PyInstaller.utils.hooks import collect_data_files, eval_statement
datas = collect_data_files('tkinterdnd2')
I add --collect-all tkinterdnd2 when executing build command.
I tried copying tkdnd2.8 to tcl8.6 as mentioned in this answer
I tried getting rid of venv and installing all the packages directly into base python interpreter.
I used --collect-all TkinterDnD2 with upperCase.
To convert a Python file to an exe, run pyinstaller.exe --collect-all TkinterDnD2 --windowed yor_app.py. This will create files and folders of the program that was created. You will find a file named TCL. Copy the tkdnd folder into it and then run the exe file

Pyinstaller - ModuleNotFoundError: No module named 'cpuinfo' [duplicate]

This question already has answers here:
Pyinstaller 'failed to execute' script
(2 answers)
Processes stuck in loop with PyInstaller-executable
(1 answer)
Closed 20 days ago.
I'm trying to package this script but I keep getting this error message
Traceback (most recent call last):
File "systeminfo.py", line 1, in <module>
ModuleNotFoundError: No module named 'cpuinfo'
[6308] Failed to execute script systeminfo
I tried this into cmd
pyinstaller -F --hidden-import="cpuinfo" systeminfo.py
I'm on the latest version of pyinstaller and pip.
This is the import section of my file:
import psutil, platform, GPUtil, cpuinfo, os, sys, wmi, winreg, getpass
from tabulate import tabulate
from datetime import datetime
When I run it, it just opens up and closes out. But when I run it through CMD, that's when I get that error message.
How do I fix this? I want to include all the modules so I can run this script on different computers that don't have python installed.
EDIT:
I fixed this issue by using this thread: Pyinstaller 'failed to execute' script
I use pycharm so this worked for me.
The only issue is whenever the CMD opens up, nothing happens. The only thing that can printed is if I hardcode a print(). Functions aren't working at all.
fix it with :
pip install py-cpuinfo

Make executable a PyQt5 project

I've tried to make a PyQt5 project an executable file.
I used a PyInstaller module, and I got a half success.
pyinstaller --clean -w -F --specpath=spec -n=project_name -i="..\resource\logo.ico" src\main.py
The executable file generated by this command did not run successfully.
The error message was like this.
pyinstaller --clean -c -F --specpath=spec -n=project_name -i="..\resource\logo.ico" src\main.py
The executable file generated by this command ran successfully.
But it has a terminal even though it is a GUI project.
The difference is just -c and -w. But one can be executed and can not one.
How should I do it?
The problem was subprocess.Popen with Python v3.7.5.
I didn't set the stdin. I set only stdout, stderr.
After I set the stdin=subprocess.PIPE, it works well.
And I want to add 1 more thing.
I've imported the win32api module with Python v3.8.0. This raises issues.
So, I've added the module pywintypes, and now the issue is resolved.
Before
import win32api
After
import pywintypes
import win32api

Creating Python Tkinter exe file with Pyinstaller problem

I have created GUI python2.7 program with Tkinter successfully without error. Now I want to make an executable file of it using pyinstaller in anaconda environment (I'm using windows 10).
Using this command
pyinstaller --onefile main.py I am able to create exe file successfully in dist folder. But when I tried to run the exe file, it showed error :
Traceback (most recent call last):
File "main.py", line 333, in <module>
File "main.py", line 90, in __init__
File "lib-tk\ttk.py", line 715, in current
_tkinter.TclError: Index 0 out of range
[22668] Failed to execute script main
Is the problem related to tkinter? I've tried the solution here : Problems with Pyinstaller with tkinter app on python 3.5 and here : How to make pyinstaller import the ttk theme? . But still same error
Try and do:
pyinstaller --onefile -w main.py
The -w flag stops python from bringing up the console, and so this could be why tkinter is failing.
Source:
This cool video
I highly recommend you watch this video as it also goes a little in depth on how to clean up after building the exe.
I used pyinstaller to create single exe file for a tkinter project, which contained several py files:
Main.py is my main python file which calls tkinter UI and I had several other python files imported to this Main.py.
Some libraries which I used include pandas,pyodbc
Open cmd in the same directory of the project; Use following command:
pyinstaller --noconfirm --onedir --windowed --icon=XYZ.ico "C:/Users/.../Tkinter_Project/Main.py"
Application was created with no dependencies. If there is any config or image files used, simply copy paste it to the 'dist' folder which gets created.

Categories