.app created with cx_freeze instantly closing on launch - python

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>

Related

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"]}

Why doesn't pynsist shortcut start python script?

I recently tried to build an installer of a python application built with PyQt5. Unfortunately, after getting the installer via .cfg file and installing it on another computer the script does not start by clicking the shortcut in the (Windows) start menu.
When trying to start the Python-script directly by double-clicking it in the according folder of the installation, Python keeps crashing since PyQt5 is not installed on the computer (although it can be found in the installation-folder). In case I manually install the package via pip install PyQt5 it works when clicking on the script, but not when using the shortcut in the menu.
I suppose this could have to do with the automatically generated file path of the shortcut, but I could not find a solution how to fix it when building the installer. I used script instead of entry_point for it - could it be that this produces my problem?
Thank you in advance!
Here is what my .cfg script looks like:
[Application]
name=sample_name
version=V0.1
publisher=sample_publisher
script=C:\path to Python script\launch_script.pyw
icon=sample_icon.ico
[Python]
version=3.6.3
[Include]
pypi_wheels=PyQt5==5.10
files=folder_with_additional_scripts
[Build]
directory=build\

build a .exe for Windows from a python 3 script

I would like building an executable for a python 3 script that:
imports pyqtgraph (with pyqt5)
imports theano and pymc3
also imports numpy, scipy, sys, os
opens a simple GUI made with qt designer and stored in a ‘.ui' file
will be distributed on machines with Windows 7+
I tried several tools (py2exe, pyinstaller, pynsist, cx_Freeze) during hours but failed each time. my 'less worse’ result was with pyinstaller (see below) without theano part (and so without a part of the script). Can anyone help me ?
I have 3 files: 2 '.py' files (1 with the main and the other with a bunch of definitions) and a '.ui' describing the GUI. The script makes some statistical analyses, then plots some curves.
Here is an example of my failure with python 3.5 and cx_Freeze (which I think is the most advanced try I had, but I’m not restricted to those tools in particular): I put my 3 files in a directory on a windows machine where everything was painfully installed (with anaconda). I add a file ’setup.py’, which for cx_Freeze is:
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python 3.5\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python 3.5\tcl\tk8.6'
os.environ['PYQTGRAPH_QT_LIB'] = 'PyQt5'
setup(
name = ‘concentrationprofiles',
version = '0.1',
description = 'simple tool to simulate concentration profiles. preliminary',
author = 'SPH',
options = dict(
build_exe = dict(
packages = ['os','sys','numpy','theano','pymc3','pyqtgraph'],#omitting ‘scipy’ ! for some reason when I put ’scipy’ in this list the building fails, but it works without… probably the ‘import scipy’ inside the code is properly interpreted
includes = ['numpy.core._methods','numpy.lib.format',
'pyqtgraph.debug','pyqtgraph.functions',
'pyqtgraph.ThreadsafeTimer','cp_util_jul17'],
include_files = ['GUI_cprofiles_jul17.ui']
)),
executables = [Executable(
script='cprofiles_jul17.py',
base='Win32GUI',
targetName=‘concentprofiles.exe'
)]
)
I then execute the command line ’python setup.py build’ in the anaconda prompt (equivalent to the command prompt to my knowledge) in the directory with the 4 files. After a lot of episodes and hours of fighting, the building looks fine (100s lines with no error message and going until the end), it creates a ‘build’ directory with a ‘exe.win-amd64-3.5’ subdirectory containing everything needed + the .exe. But when I try and run this .exe I get nothing: no error message, no console or window opening, no fast opening-closing and I can’t find a log… just nothing
I tried to change the ‘base’ option from ‘Win32GUI’ to base=’Console’ and base=None. In these cases I guess there is a fast console-opening-closing that I cannot read since I don’t find the log.
Here are few other bad results during other tries:
py2exe: turns out to be incompatible with my usual python 3.6, so I downgraded to 3.5. But even in 3.5, after a few lines it froze: once again no error message, no console or window opening, no fast opening-closing and I can’t find a log… just nothing. not even a ‘build’ directory. Another time I also tried an alternative with python 3.4 but I got an error concerning a missing ‘msvcr100.dll’ that I tried to install following instructions on forums. When I eventually got the permission to modify system directories, an instruction ‘regsvr32’ failed (isn’t this for 32 bits only ? but there is no ‘regsvr64’…). I eventually gave up
pyinstaller: see updates
pynsist: The principle of pynsist is that you don’t get an executable but an installer only. Why not ? I don’t need a .exe as long as I can distribute the code. Unfortunately, after building the installer (with no error) and installing it (again with no visible error), the program gives nothing, like in the cx_Freeze case.
I can add a link to the script files if you want/need.
update august, 18, 2017, 9:20am
Following the suggestion, I opened a new post concerning pyinstaller: build a .exe for Windows from a python 3 script importing theano with pyinstaller.
I invite you to answer the pyinstaller concerns there. This question will be marked as answered if my problem is solved with py2exe or cx_freeze.
update september, 2, 2pm:
I eventually managed to build a .exe with pyinstaller after many episodes.
Unfortunately I failed to deal with the ‘theano’ module (that is required in my case by the ‘pymc3’ module) and I had to modify the .py files and give up part of the application. Could anyone help me building a .exe for windows 7+, with the ‘theano’ module ?
To create an executable file of your Python program, run the following command in CMD.First you need to install pyinstaller, with the following command:
pip install pyinstaller
And then do the following to create one executable file of your Python program, first, Go to your program path, (with cd) where your Python (.py) file is, and then:
pyinstaller -w -F YourPyFile

Convert a Python (3.5.2) File into an exe?

is there any surefire way to convert a Python (3.5.2) File into an exe? I have seen Pyinstaller, py2exe and cx_Freeze. cx_Freeze does not have a Python 3.5 version, only 3.4 so it isnt compatible. Py2exe works only for Python 2 and while I had some success with Pyinstaller, it returned an error relating to 9130 WARNING: hidden import "pygame._view" not found! (the only one as I can see).
The exe. file was created but malfunctioned and stopped working.
Any advice?
I used py2exe to convert python 3 files to exe files. I haven't tested with version 3.5 but this website says that this version of py2exe works with any python 3 versions.
Download and install py2exe
Navigate to your python folder.
Create new text file called setup.
Insert these commands:
from distutils.core import setup
import py2exe
setup(console=['nameofyourpyfile.py'])
Close the text file and open cmd.
Navigate to your python folder using command cd.
Enter this command: python setup.txt py2exe
Press enter and your done navigate to folder called dist and find your exe file.
If it doesn't work install program called pywin32 and try again. If pywin32 doesn't help then let me know I will help you for sure :D

Compiling a non-standard module into an executable file with PyInstaller

Background: I have had success in the past installing and using Pyinstaller to transform my python projects into one-file executables. I don't think it is an issue with my source code or pyinstaller files.
Problem: I used a free, open-source library/module called easygui imported into my source code to build an application. The application works perfectly run natively or through the Python IDE. I am pretty sure the problem is that Pyinstaller is not finding the EasyGUI module to import (it automatically includes and compiles any libraries you import in the script).
Actions: My python folder is not in the C:\ drive, it is in the E:\ drive. I'm able to access the pyinstaller path in "E:\program files\python" but it is not reading the easygui library, I don't think. I installed pyinstaller and easygui using pip.
Reading a LOT of pyinstaller's documentation i tried to run it to include a paths dir like:
E:\Program Files Hard Disk\Python\Scripts>pyinstaller --paths
DIR "E:\Program Files Hard Disk\Python" --onefile "E:\Program Files\Python"
It does output the single executable in the build file but does not launch correctly. From what I can see in the console window the brief moment it's up, it looks like an easygui issue. Here is the result of attempting to launch the executable from the command-line:
Here is the compiling in the command window:
Please help

Categories

Resources