cx_Freeze app cannot find tk.tcl - python

I would like to distribute a tkinter app by using cx_Freeze.
I can run the myapp.py from command line.
cx_Freeze creates a folder named "exe.macosx-10.6-x86_64-3.4", and the osx exe works from here.
The osx exe from within myapp.app yields the following error:
`tkinter.TclError: Can't find a usable tk.tcl in the following directories:`
....
This probably means that tk wasn't installed properly.
Here is my stripped-down setup.py
build_exe_options = {"modules": ["tkinter", "time", "requests", "threading", "os"]}
setup(name="myapp",
option={"build_exe": build_exe_options},
executables=[Executable("myapp.py",
base=base)]
)
Edit: I attempted this with python 2.7, and it works. The line "This probably means that tk wasn't installed properly" is likely correct.

I ran into the same problem on mac Yosemite. The system python is 2.7 and I'm using python3. I found that python2.7 build successfully with tkinter but 3.4 does not.
Haven't figured out how to make python3.4 work yet.

Related

python cx-freeze executable and original python file look different

I made a python file, it uses the module tkinter.messagebox, I made it an executable file using cx-freeze , but the messagebox from the executable looks different from the messagebox made with the python code.
messagebox looks different
how do I make the executable's messagebox look like the messagebox made using the python code?
here is my cx-freeze script:
from cx_Freeze import setup, Executable
setup( name = "script",
version = "1.1",
description = "messages",
options = {"build_exe": {"packages": ["os"]}},
executables = [Executable("msg.py", base="win32gui")])
to make the exe, I typed python setup.py build in the command line.
also, please don't ask me to use pyinstaller because there's problems with it for me.
I used pyinstaller to make the executable instead, it worked finally.
I think it's something to do with the win32gui base. in pyinstaller, when i used the -w parameter, the messagebox also looks like the ugly one.

Error using cx_freeze with tkinter

I prepared the script for a GUI using Tkinter that is working well when I run it as a script. But I wish to share my application to others who don't have Python installed on their computer. The 'python setup.py build' is running without error and creates the required directories and files', but gives lot of errors when I run the .exe file.
The packages that I'm importing in the script are:
#gdal
#Tkinter
#cv2
#sklearn
I'm using a Windows 7 professional Service Pack 1, 32-bit machine.
#Python version : 3.5.5
#cx_Freeze version: 4.3.3
Please check the error screen-shot below:
I cannot be sure without your actual setup script but it looks like you just need to add numpy and numpy._methods to your packages list.
build_exe_options = {"packages": ["numpy", "numpy._methods"]}

py2app does not work with tkinter

if I put "import tkinter" in my Python (3.6) file the mac app I get with py2app does not work.
py2app works just fine with other Python files importing other packages (math, time, random etc) only importing tkinter raises this problem
Solved but I'm not sure it should have to work like this.
I think the problem is that Mac works with Python 2.7 (system Python) which raises an error when it gets "import tkinter".
So I installed with Homebrew Python 2.7, redesigned my modules written in P 3.6 ("import Tkinter" etc.) py2app-ed it and everything went fine.

.app created with cx_freeze instantly closing on launch

I am making a really simple app in python, using Tkinter as GUI, and cx_freeze to build it.
It all is in a simple "sleep.py" file.
The setup.py file used by cx_freeze is as follows :
from cx_Freeze import setup, Executable
executables = [
Executable('sleep.py', base=None)
]
setup(name='Sleep Calculator',
version='0.90',
description='Sample cx_Freeze script',
executables=executables
)
The sleep.py file is launching correctly :
- When launched in MacOS from the terminal
- When built in MacOS using python3 setup.py build
- When built in Windows using python3 setup.py build_exe and then copying the tkinter files manually into the build folder created by cx_freeze
So I have a sleep.py file that is working both from Windows and Mac, a script that is working in MacOS, and an EXE that is working on Windows.
However, when trying to build to a .app using python3 setup.py bdist_mac, I get an app that is instantly closing on launch.
The only message I get during the launch, in the console, is
"Loading Preferences From User CFPrefsD For Search List"
During build, I get multiple
fatal error: /Library/Developer/CommandLineTools/usr/bin/otool: internal objdump command failederrors. Xcode is not installed, but CommandLineTools is.
I know almost nothing of OS X at the moment, so any help is welcome,
Thanks !
I had the same problem where an app with cx_freeze would close as soon as I opened it, but running the executable inside the package would work.
It was solved for me by opening the built package and editing the info.plist file.
After adding a bundle identifier it started as it should.
<key>CFBundleIdentifier</key>
<string>My App</string>

Python3.4 Py2exe, error - name 'WinDLL' is not defined

I use Ubuntu, Python 3.4 and try to compile my py scripts to exe using py2exe.
Unfortunately When I try to use command 'build_exe', it generates error!
Could anybody help me to solve it or advise how to compile py project to exe in another way?
Error code:
NameError: name 'WinDLL' is not define.
py2exe is for windows...
On linux you can try PyInstaller:
http://www.pyinstaller.org/
PyInstaller is now able to build Windows executables when running
under Linux. See documentation for more details.
The py2exe module needs to be run from within a command prompt shell (aka Windows terminal) to make a Windows executable, since just like pyinstaller, "they use the OS support to load the dynamic libraries, thus ensuring full compatibility". That's why you get the ''WinDLL' is not defined' error when using the py2exe module in a bash shell.
py2exe works until python-3.4 and pyinstaller works until python-3.7. The latest version at time of writing is 3.8. Use the python module virtualenv from command prompt to get the adeqaute python version running (without replacing your current python set-up), and make your executable file. Here is my answer with code. --> Make sure to add python to your Windows path on install, so you can use the pip and python commands in command prompt. Otherwise you have to replace these commands in my answer for their fullpath, e.g. C:\Users\jakethefinn\python37\pip.exe and C:\Users\jakethefinn\python37\python.exe respectively.
If you install python from Microsoft Store, the files pip.exe and python.exe are automatically added to path.

Categories

Resources