pyinstaller can't find package Tix - python

I am trying to create an executable with pyinstaller for a python script with tix from tkinter. The following script also demonstrates the error:
from tkinter import *
from tkinter import tix
root = tix.Tk()
root.mainloop()
I have Python 3.9 installed and the script runs fine and works as intended but after using pyinstaller to create an executable, the .exe file fails to run because it can't find the package Tix.
One of the solutions mentioned here which is to copy the C:\Python39\tcl\tix8.4.3 folder to the dist directory for the executable worked for me. The executable runs as intended after copying the folder, but I would like to package the script into one exe without needing to supply the tix8.4.3 folder.
Is there anyway to package the tix folder when building the executable with pyinstaller?

It works for me using below command to generate the executable:
pyinstaller -F --add-data C:\Python38\tcl\tix8.4.3;tcl\tix8.4.3 main.py
Note that I use PyInstaller 4.7 and Python 3.8.12 under Windows 7.

you have error in code:
from tkinter import *
from tkinter import tix
root = tix.Tk() # Here it was TK
root.mainloop()

Related

App using TKinterModernThemes made with PyInstaller gives the error "invalid command name "set_theme""

I've been trying to make an app using tkinter, TKinterModernThemes, and turn it into an executable with PyInstaller, and I've had no luck. Every time I try to use any kind of module using ttk themes, I run into some sort of error. I decided to settle on using the TKinterModernThemes module. Making an exe using PyInstaller gives me the following error:
File "TKinterModernThemes\__init__.py", line 66, in __init__
_tkinter.TclError: invalid command name "set_theme"
I've tried including both tkinter and TKinterModernThemes as a hidden import in PyInstaller, trying with and without --onefile, and using Nuitka instead (same error). Any help would be wonderful.
I changed manually my path here ThemedTKinterFrame.__init__, at line 64 like this
self.root.tk.call("source", "/home/pi/.local/lib/python3.7/site-packages/TKinterModernThemes/themes/" + theme.lower() + "/" + theme.lower() + ".tcl")
and it works.
pyinstaller --noconsole --onefile --collect-data TKinterModernThemes --collect-data PIL .\FILENAME.py
SAVED MY LIFE!!!
This is now fixed in version 1.9.0 - the issue was the '/../' that I had in the library to move up a directory - the os.path.abspath handles this better.

Failing to create a .exe file with Python and PyQt5

I`m trying to make an executable from my python script called ProyectoNew.py. It works with a folder called "Imagenes" and another called "ModulosExternos", and a PyQT5's .ui file like this:
Here`s the Code posted in GitHub: https://github.com/TheFlosh/ProyectoSoftware.git
I`ve tried to use Pyinstaller, Py2Exe and CXFreeze but it didn't worked. Using each one of these modules to create a .exe file I've got the same result when I tried to execute it in another PC, as shown here:
On the LEFT of the picture you can see what I get after using pyinstaller (or Py2Exe), on the right you can see what I need to show.
Here are the modules that I use in my code ("ModulosExternos" is the folder where I put some particular modules that my code needs):
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import pyttsx3
from pyttsx3.drivers import sapi5
import PyQt5
import sip
import os
from ModulosExternos import Boton_1,Boton_2,Boton_3,Boton_4,Boton_Final,Listas_Pictogramas, Frases_Completas
And here is the last part of it, to instantiate the GUI:
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
GUI = ProyectoNew()
GUI.show()
sys.exit(app.exec())
I`ve read a lot of posts on the internet that recommended creating Setup.Py file to initiate the process of creating an executable file of my project. These are some examples of what I did with two of them:
With CX_Freeze:
import sys
import os
from cx_Freeze import setup, Executable
files = ['icono.ico','/Imagenes']
target = Executable(
script = "/ProyectoNew.py",
base = 'Win32GUI',
)
#Setup
setup(
name = "Proyect2",
version = "1.6",
description = "Software",
author = "----",
options = {'build_exe': {'include_files' : files}},
executables = [target]
)
With Py2Exe:
from cx_Freeze import setup, Executable
setup(name = "Proyect2",
version="1.0",
description = "Software",
executables = [Executable("ProyectoNew.py")],)
With Pyinstaller I typed: python --nowindowed --onefile ProyectoNew.py but I constantly got the same result as shown before.
I think that when I execute Pyinstaller, the .exe file doesn`t load the modules and the images that I use. What am I missing while creating the file? What do I need to do to execute the .exe file in another PC?.
I would prefer to use pyinstaller,but using any one of these will help me.
What's is wrong with that? You get some kind of error? Please edit your question with that.
With pyinstaller and this command, you should be able easily build an executable file:
pyinstaller [FILE].py -w -F
This command generate a /dist folder with the neccesary files and .exe file to run
*-w param is for do not provide a console window for standard i/o
*-F param is for one-file bundled executable
You can check more params here
PD: Before, you need obviously install pyinstaller:
pip install pyinstaller

Way to call new modules after exe is compiled with pyinstaller?

pyinstaller --onefile script.py
script.py
while True:
x=raw_input('enter code: ')
exec(x.strip())
copy new module into root of script.exe
'newmodule'
run script.exe
enter code: import newmodule
-------this errors, module not found
a way to do this?

Freeze a program created with Python's `click` pacage

I've got a command line program that uses Python's click package. I can install and run it locally, no problem with:
pip install --editable . # (or leave out the editable of course)
Now, I'd like to create an executable file that can be distributed and run standalone. Typically, since I'm in a Windows environment, I would use one of py2exe, pyinstaller or cx_Freeze. However, none of these packages work.
More specifically, they all generate an executable, but the executable does nothing. I suspect this problem is because my main.py script doesn't have a main function. Any suggestions would be very helpful, thanks in advance!
Can reproduce the issues with code copied from here.
hello.py
import click
#click.command()
def cli():
click.echo("I AM WORKING")
setup.py
from distutils.core import setup
import py2exe
setup(
name="hello",
version="0.1",
py_modules=['hello'],
install_requires=[
'Click'
],
entry_points="""
[console_scripts]
hello=hello:cli
""",
console=['hello.py']
)
If someone could supply a working setup.py file to create an executable and any other required files, that would be much appreciated.
From the console:
python setup.py py2exe
# A bunch of info, no errors
cd dist
hello.exe
# no output, should output "I AM WORKING"
I much prefer pyinstaller to the other alternatives, so I will cast an answer in terms of pyinstaller.
Starting click app when frozen
You can detect when your program has been frozen with pyinstaller, and then start the click app like:
if getattr(sys, 'frozen', False):
cli(sys.argv[1:])
Building an exe with pyinstaller
This simple test app can be built simply with:
pyinstaller --onefile hello.py
Test Code:
import sys
import click
#click.command()
#click.argument('arg')
def cli(arg):
click.echo("I AM WORKING (%s)" % arg)
if getattr(sys, 'frozen', False):
cli(sys.argv[1:])
Testing:
>dist\test.exe an_arg
I AM WORKING (an_arg)

Python os.popen error wxPython

I created a executable with py2exe for a wxpython app what working fine, when starting the executable created gives me an error about os.popen. code that creates the executable is:
# setup.py
from distutils.core import setup
import py2exe
setup(name="GridSimple",scripts=["GridSimple.py"],)
http://i.stack.imgur.com/u9Sj8.jpg
Here about this problem http://wiki.wxpython.org/CreatingStandaloneExecutables?highlight=%28unicows.dll%29#py2exe
They say "include the file unicows.dll" Where is it?

Categories

Resources