Compiling a python script I've written as an .exe and .app - python

To preface, I have very little python knowledge, so the simplest solution will probably be the best one.
Essentially, I've written a program that takes user input and writes it to a text file. I've created a GUI with Qt and PySide. What I want to do now is to compile everything together to be a single .exe file that I can just drop into the laps of anyone who wants to use it. Basically, it needs to be able to run out of 1 single .exe file on a computer that doesn't necessarily have any of the python libraries installed that mine does.
The only imports on the program are
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from math import *
in case those are important to the compiling. Thank you for the help, I appreciate it.
P.S. It's for my grandmother, who has nearly no knowledge of computers whatsoever. If possible, it'd be awesome if it would just...open. I don't mind if it has to run something in cmd to install all the python stuff, as long as the .exe from which the program runs is still JUST an .exe.

I suspect your grandmother uses windows in which case I would recommend using py2exe.
Here is probably all than you need...
1). create the below script and modify the last line of it to be the name of the actual script (see its last line)
#execmaker.py would be the name of this file
#stable version
from distutils.core import setup
import py2exe
includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
'tk84.dll']
setup(
options = {"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 3,#dont bundle else unstable
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
windows=['My_Script.py'] #this is the name of your actual script
)
2). Then you can go to the directory where this script and your actual script resides via cmd and then type
python execmaker.py py2exe
You now should have a working executable. Now a you can double click on the executable and your script will run. oh yeah and if you have questions follow this guy's instructions...he is good!
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/

download pyinstaller (http://www.pyinstaller.org/)
open your cmd prompt
cd folder
c:\pyinstaller\pyinstaller.py --noconsole --onefile my_script.py
the exe should be found in the dist folder that is created

Related

msi created in cx_freeze does not install program

I have a python program I've created and turned into an exe with cx_freeze. When just creating the exe with "python setup.py build", everything works great. Now I am trying to create an installer for it by using "python setup.py bdist_msi" and everything seems to work great at first.
The installer pops up and asks me to select a directory. After clicking next, Windows requires me to accept that I'm installing from an unknown publisher. After accepting, the next page immediately jumps to "Completing the (program) installer", and "click finish to exit the installer". After clicking finish, I cannot find my program file anywhere, and the installer appeared to do nothing.
I've tried running this on multiple computers, and nothing seems to work. I think this is an issue with my setup.py script. This does include several qml files and some pictures in my "Resources" folder, and there are several csv's in my "Data-and-executable" folder, plus a exe that is called on by my python script.
from cx_Freeze import setup, Executable
# dependencies
build_exe_options = {
"packages": ['atexit', "os", "sys", "csv", "time", "functools", "PySide2.QtCore", "PySide2.QtWidgets", "PySide2.QtUiTools", "PySide2.QtQuick", "PySide2.QtQml", "PySide2.QtGui", "shiboken2"],
"include_files": ['README.md', r'Resources','inputClass.py', 'selections.py','simulationOutput.py',
'Data-and-executable'],
"include_msvcr": True,
"excludes": ["Tkinter", "Tkconstants", "tcl", ],
"build_exe": "build",
}
bdist_msi_options = {
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % ("Name", "Product"),
}
executable = [
Executable("main.py",
base="Win32GUI",
targetName="product.exe",
icon= r"Resources\logo_icon.ico"
)
]
setup(name = "Product",
version = "0.3",
description = "Simulator",
options={"bdist_msi": bdist_msi_options,
"build_exe": build_exe_options},
executables=executable
)
There are no error messages or anything else to tip me off as to what's going on. Even calling my .msi with cmd does not provide any insight.
Smh. I had all of my files just in the "build" folder, and not the "build/exe.win-amd64-3.6" folder. It works.

Creating an Exe with Selenium Module: Py2exe/Pyinstaller

I've looked everywhere. Stackoverflow, various messageboards, the py2exe website, the pyinstaller website...nothing is helping. Including the selenium module, particularly making an exe that supports firefox, seems impossible. I am starting to pull out my hair because using either py2exe and pyinstaller is becoming a huge headache.
Both py2exe and pyinstaller have their share of problems.
My goal is to make one single exe file, without any extra directories, so that other people can use my program if they do not have python/modules.
With py2exe, if I create a setup.py file as such
from distutils.core import setup
import py2exe
setup(
name='Ask Alfred',
data_files = [('Drivers', ['Drivers/chromedriver.exe',
'Drivers/webdriver.xpi','Drivers/webdriver_prefs.json'])],
version='1.0',
description='Find emails fast!',
author='Me',
windows=[{'script': 'alphy.py'}],
options={
'py2exe':
{
'skip_archive': False,
'optimize': 2,
}
}
)
it will create an exe in the dist folder and a Drivers folder with the files I need, however, if I try to run the exe it will tell me that it could not find these files (because it is looking for them in the library.zip folder). On top of that, my GUI looks terrible (fonts are now grey instead of black and images with white backgrounds now have grey backgrounds).
With pyinstaller, if I use the "--onefile" flag when creating the exe it does not work at all/neither firefox nor chrome gets started.
With either, I only get workable results if I choose to not archive/not make one file. In that case, pyinstaller delivers a fully working solution.
Try this:
options={
'py2exe':
{
'skip_archive': True,
'unbuffered': True,
'bundle_files': 2, #assuming you dont want to include the python interpreter
'optimize': 2,
},
},
zipfile = None

cx_freeze: Not a directory

I'm trying to create a binary on Linux (Manjaro Linux, x86_64, python 3.4).
My app is a GUI software, written with PyQt.
Here is my setup.py:
import sys
import os
from cx_Freeze import setup, Executable
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
my_data_files = ["./images/", "./journals/", "./config/"]
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"],
"excludes": [
"tkinter"
],
'includes': [
'sip',
'PyQt4.QtCore',
'PyQt4.QtGui',
'PyQt4.QtNetwork',
'PyQt4.QtSql',
'scipy.sparse.csgraph._validation',
'sklearn.utils.sparsetools._graph_validation',
'scipy.special._ufuncs_cxx'
],
'include_files': my_data_files
}
setup(name = "guifoo",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("gui.py", base=base)])
For now, I'm just starting. The "includes" part in the options is what I used when I compiled my binary with py2exe (it worked, but I want a unique tool to compile for all the platforms).
When I start the compilation with
python setup.py build
everything seems to work fine, but when I try to start the binary, I have this exception:
NotADirectoryError: [Errno 20] Not a directory: '/home/djipey/Desktop/test/build/exe.linux-x86_64-3.4/library.zip/text_unidecode/data.bin'
So I assume I have a problem with the module text_unidecode, but I can't really identify what the problem is.
Could you give me a hand please ?
EDIT:
Ok, sorry for the lack of precision, I didn't copy/paste the whole error message:
File "/usr/lib/python3.4/site-packages/text_unidecode/__init__.py", line 6, in <module>
with open(_data_path, 'rb') as f:
NotADirectoryError: [Errno 20] Not a directory: '/home/djipey/Desktop/test/build/exe.linux-x86_64-3.4/library.zip/text_unidecode/data.bin'
I think the issue can come from text_unidecode, but I don't know why. I installed it without any problem on my computer.
https://github.com/kmike/text-unidecode/blob/master/src/text_unidecode/init.py
EDIT 2:
If I integrate the code of text-unidecode (it is basically a single function) in my own code, it works. I think I know why I have this issue. In text-unidecode, there is a file called "data.bin" which contains data used by the function of text-unidecode. It is a part of the library, but it is not added to library.zip when I use cx_freeze. So text-unidecode can't work.
Is there an elegant way to solve this with cx_freeze ? Like an option, to add data files to library.zip ?

Working with cx_Freeze - how to include all necessary files in .exe?

I want to make a self-contained .exe file.
I have managed to use cx_Freeze to build one that works on my machine, but it is throwing an error about needing the .dlls when I sent it to someone. I read a few of the similar questions, which is how I ended up including packages in the build options.
I suspect that once I get past this particular problem, I will end up needing to include other stuff in the .exe....any help getting around that pitfall is appreciated! The end user needs to be able to only use the .exe and not have to install other files.
Here is my current setup.py:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
build_options = {"includes" : [ "re", "atexit"], "packages": ["PyQt4.QtCore", "PyQt4.QtGui"]}
setup( name = "Hex Script Combination",
version = "0.1",
description = "Contact (info) with questions",
options = {"build_exe" : build_options},
executables = [Executable("Project.py", base=base)])
ETA:
I tried IExpress, and I'm running into this error:
(Picture uploaded but for some reason, neither picture in this post is showing)
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in <module>
code = importer.get_code(moduleName)
ZipImportError: can't find module 'projec~1__main__'
I did NOT find a way to do exactly what I wanted. I did, however, discover that I was getting an installer I wasn't aware of for distribution that did install everything that was in my exe directory.
File path was ~\dist, and it contained only an .msi file. Launching it installed everything that was in ~\build\exe.win32-2.7

Error after creating exe with Py2exe

Py2exe seems to run fine although it does mention that a few modules maybe missing.
I had been using the windows option (in my py2exe script) to remove the console window but realized that the process still remained open even after I closed down the gui window i.e. I could still see the process still in task manager... So I switched to using the console option and found the below error printed there. I believe this error is preventing the the app from closing. Apart from that the app runs fine.
Iv tried creating an exe from a very simple wxPython GUI app but even then I still get this error however I have no problem creating executables from apps that do not include wxPython.
Debug: src/helpers.cpp(140): 'createActCtx' failed with error 0x0000007b (the filename, directory name, or volume label syntax is incorrect.).)
Python: 2.6.6
wxPython: 2.8.11.0
Windows 7
py2exe: 0.6.9
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
import glob
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll',]#'msvcp90.dll']
packages = []#'wx.lib.pubsub']
data_files = [("resources", ['resources/1187958_90214884.jpg'])]
packages = ['wx.lib.pubsub',]
options = {'py2exe': {'compressed': 3,
'optimize': 2,
'excludes': excludes,
'packages': packages,
'dll_excludes': dll_excludes,
'bundle_files': 1,
'dist_dir': 'dist',
'xref': False,
'skip_archive': False,
'ascii': False,
'packages': packages,
'custom_boot_script': '',
}
}
#windows=[{'script':'gui.py'}]
for script in ["gui.py"]:
windows=[{
'script':[script]
}]
setup(options=options, console=[script], zipfile=None, data_files=data_files)
I've had very little trouble getting wxPython code to compile to an exe using py2exe. I have a tutorial that you can try here:
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
I have had some issues with the new version of pubsub that is included with 2.8.11.0. You can read the thread here: http://bit.ly/emoHEr
I ended up reverting to the previous version of wx that day mainly because I didn't have time to figure out what I was doing wrong. I don't know if that's the problem that you're having though.

Categories

Resources