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"]}
Related
I have never made an executable application before but from what I have read its pretty easy, using py2exe to generate the exe.
But I have a GUI that uses Selenium to scrape data from a backend (No I can not use API calls). How do I add chromedriver to the executable? Also, would all the imports go along when using a compiler?
When you compile a .py file into an .exe (from my personal experience) all of the imports are included.
I would personally suggest using pyinstaller. I had quite a few problems using py2exe and as a beginner I found pyinstaller much more user-friendly and easier to troubleshoot.
As compiling a file does not alter the .py file, I would suggest getting it to a fully working state and trying it. If it doesn't appear to work or if some of the imports are lost, we can troubleshoot with the error code.
You can also use cx_Freeze to create an executable from your python script.
You can install cx_Freeze by issuing the command
python -m pip install cx_Freeze --upgrade
in a cmd prompt / terminal.
As far as tkinter is concerned, you'll find a working example of how to freeze a tkinter-based application with the current version of cx_Freeze in this answer. In the setup.py script you find there, you need to replace the name of the Executable by the name of your main script. Place this setup.pyin the same directory than your main script and run
python setup.py build
from a cmd prompt / terminal.
As far as chromedriver is concerned, I've no experience, if you choose this approach and still have problems, please add the exact error message and a Minimal, Complete, and Verifiable example to your question.
I've created a kivy app that works perfectly as I desire. It's got a few files in a particular folder that it uses. For the life of me, I don't understand how to create an exe on mac. I know I can use pyinstaller but how do I create an exe from mac.
Please help!
For pyinstaller, they have stated that packaging Windows binaries while running under OS X is NOT supported, and recommended to use Wine for this.
Can I package Windows binaries while running under Linux?
No, this is not supported. Please use Wine for this, PyInstaller runs
fine in Wine. You may also want to have a look at this thread in the
mailinglist. In version 1.4 we had build in some support for this, but
it showed to work only half. It would require some Windows system on
another partition and would only work for pure Python programs. As
soon as you want a decent GUI (gtk, qt, wx), you would need to install
Windows libraries anyhow. So it's much easier to just use Wine.
Can I package Windows binaries while running under OS X?
No, this is not supported. Please try Wine for this.
Can I package OS X binaries while running under Linux?
This is currently not possible at all. Sorry! If you want to help out,
you are very welcome.
This is easy with Pyinstaller. I've used it recently.
Install pyinstaller
pip install pyinstaller
Hit following command on terminal where file.py is path to your main file
pyinstaller -w -F file.py
Your exe will be created inside a folder dist
NOTE : verified on windowns, not on mac
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
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>
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.