My application looks different after I freeze it using cx_freeze (I'm using Gui2Exe to create and run the cx_freeze script) and when I run it using the python interpreter.
[As I'm not allowed to post images, here are the links to the UI, edit?]
Script run:
Application as run from the command line
Frozen run:
Application as run after being frozen by cx_freeze
I have tried both including and not including the manifest file in the cx_freeze script, yet I'm unsure what could be causing the application UI to change so dramatically.
Here is the cx_freeze script:
# ======================================================== #
# File automagically generated by GUI2Exe version 0.5.3
# Copyright: (c) 2007-2012 Andrea Gavana
# ======================================================== #
# Let's start with some default (for me) imports...
from cx_Freeze import setup, Executable
# Process the includes, excludes and packages first
includes = ['ast', 'gobject', 'gtk']
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
packages = ['BeautifulSoup', 'mechanize', 'pygtk']
path = []
# This is a place where the user custom code may go. You can do almost
# whatever you want, even modify the data_files, includes and friends
# here as long as they have the same variable name that the setup call
# below is expecting.
# No custom code added
# The setup for cx_Freeze is different from py2exe. Here I am going to
# use the Python class Executable from cx_Freeze
GUI2Exe_Target_1 = Executable(
# what to build
script = "moodle-downloader.py",
initScript = None,
base = 'Win32GUI',
targetDir = r"md",
targetName = "moodle-downloader.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = True,
appendScriptToLibrary = True,
icon = r"C:\Users\Nasser.Al-Hilal\Dropbox\CodeN\Projects\Applications\Personal\MoodleDownloader\res\md.ico"
)
# That's serious now: we have all (or almost all) the options cx_Freeze
# supports. I put them all even if some of them are usually defaulted
# and not used. Some of them I didn't even know about.
setup(
version = "0.3",
description = "An app to assist in downloading assignment submissions from Moodle LMS.",
author = "Nasser Al-Hilal",
name = "Moodle Downloader",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages,
"path": path
}
},
executables = [GUI2Exe_Target_1]
)
# This is a place where any post-compile code may go.
# You can add as much code as you want, which can be used, for example,
# to clean up your folders or to do some particular post-compilation
# actions.
# No post-compilation code added
# And we are done. That's a setup script :-D
I would prefer if I can get the application to look the same as when run from the interpreter.
For you to work you have to download gtkruntime, install it on your system, then copy the lib folder and share your generated build folder, then copies the contents of the bin folder gtkruntime your build folder, and then you work.
My installation:
windows 7
Python 2.7.9
GTK2 (python -m pip install pygtk)
pycairo (1.8.10) pygobject (2.28.3)
pygoocanvas (0.14.2)
pygtk (2.24.0)
pygtksourceview (2.10.1)
cx-Freeze (python -m pip install cx-Freeze)
cx-Freeze (4.3.4)
cx-freeze compile command:
\Py279\Scripts\cxfreeze MyGUIapp.py --target-dir somewheredir --base-name=Win32GUI
(in essence, all done without any setup command files, although some can be created :) )
once cx-freeze compiles to exe and copy dll it believes that are needed I get motif/x11 look/feel however, when I add to somewheredir all .dll files from:
\Py279\Lib\site-packages\gtk-2.0\runtime\lib\gtk-2.0\2.10.0\engines\
to:
somewheredir\lib\gtk-2.0\2.10.0\engines\
I get windows look and feel.
Files found there in my case are:
libpixmap.dll
libsvg.dll
libwimp.dll
that's all.
Plus:
some further design customization influence can be achieved by creating .gtkrc-2.0 in the user's home folder c:\Users\myuser. Namely one can influence default font face and size used, window background color and such. For example, following code (hints from elsewhere)
style "win32-font" {
# make default font larger
font_name = "Sans 12"
# set the background to a light grey
bg[NORMAL] = "#f6f6f6"
}
class "*" style "win32-font"
placed in c:\Users\myuser\.gtkrc-2.0 would change 'default' font size and change top window background for pygtk applications run by user (meaning each user can set its own preferences there).
This is just a translation of Blasito's answer:
"For this to work correctly, first download and install GTK-runtime on your computer. Then navigate to GTK-runtime installation folder (in Program Files) and copy over the lib and share folders over to the generated build folder. Finally, copy the contents of the bin folder (in the installation directory) into the build folder."
I can verify this works.
Related
I know there have been a bunch of questions already asked regarding this but none of them really helped me. Let me explain the whole project scenario so that I provide a better clarity to my problem. The directory structure is somewhat like this shown below:
Project Directory Layout
I need to convert this whole GUI based project (The main file is using Tkinter module to create GUI) into main.exe which I can share with others while making sure that all the additional files work exactly the same way it is working now when I run this main.py via Command Prompt. When I use this command with pyinstaller -
"pyinstaller --onefile --noconsole main.py"
It creates main.exe which shows "Failed to execute script" on running. Please provide me a detailed explanation on what should I do to achieve what I have stated above. Thank you in advance.
pyinstaller uses a few dirty tricks to compress a bunch of files into one
I recommend using cx_Freeze instead along with inno setup installer maker
do pip install cx_Freeze to install that and go here for inno setup
then copy the following into a file named setup.py in the same folder as your project
from cx_Freeze import setup, Executable
setup(name = "YOUR APP NAME" ,
version = "1.0.0" ,
description = "DESCRIPTION" ,
executables = [Executable("PYTHON FILE", base = "Win32GUI")]
)
lastly run python setup.py build
if you want as onefile download this file here
just edit the file a bit and use inno compiler to make into installer
Suppose our project has the following structure.
MyApp
|-models
| |-login.kv
|-data
| |-words.json
| |-audio.tar.gz
|-fonts
| |-FredokaOne.ttf
|-images
| |-gb.pngsound.png
| |-icon.ico
|-main.py
|-main.kv
|-draw.py
|-image.py
and depends on the following packages:
- kivy
- kivymd
- ffpyplayer
- gtts
First things first is to install cx_Freeze.
pip install cx_Freeze
Copy the following into a file named setup.py in the same folder as your project.
# https://cx-freeze.readthedocs.io/en/latest/distutils.html
import sys
from cx_Freeze import setup, Executable
includes = []
# Include your files and folders
includefiles = ['models/','data/','fonts/','images/','main.kv','draw.py','image.py']
# Exclude unnecessary packages
excludes = ['cx_Freeze','pydoc_data','setuptools','distutils','tkinter']
# Dependencies are automatically detected, but some modules need help.
packages = ['kivy','kivymd', 'ffpyplayer','gtts']
base = None
shortcutName = None
shortcutDir = None
if sys.platform == "win32":
base = "Win32GUI"
shortcutName='My App'
shortcutDir="DesktopFolder"
setup(
name = 'MyApp',
version = '0.1',
description = 'Sample python app',
author = 'your name',
author_email = '',
options = {'build_exe': {
'includes': includes,
'excludes': excludes,
'packages': packages,
'include_files': includefiles}
},
executables = [Executable('main.py',
base = base, # "Console", base, # None
icon='images/icon.ico',
shortcutName = shortcutName,
shortcutDir = shortcutDir)]
)
Lastly run.
python setup.py build
This command will create a subdirectory called build with a further subdirectory starting with the letters exe. and ending with the typical identifier for the platform that distutils uses. This allows for multiple platforms to be built without conflicts.
On Windows, you can build a simple installer containing all the files cx_Freeze includes for your application, by running the setup script as:
python setup.py bdist_msi
Cx_freeze references
Doc
Git Hub
I created a new script with cx_freeze's template. Then I'm running python setup.py build to create the exe. If I move main.exe to the root folder cx_freeze test it will fail to run.
All I want is to move .exe up 1 or two directories.
Here's my code:
main.py
foo = input("Complete")
setup.py:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(
packages = [],
excludes = [],
includes = ["atexit"]
)
# include_files=[]
base = 'Console'
executables = [
Executable('main.py', base=base, targetName = 'main.exe')
]
setup(name='freeze test',
version = '1',
description = '.',
options = dict(build_exe = buildOptions),
executables = executables)
I thought http://cx-freeze.readthedocs.org/en/latest/faq.html#using-data-files might have some help, but since the files are in the subdirectory, I can't use os module?
That feature is not available in 4.x but will be available in 5.x when it is made available. The current source has this capability so if you can compile it you can have it today; otherwise, you'll need to wait for the official release which I hope will be soon.
I am writing an installation program for a larger program I am writing, and I am using CxFreeze to convert it to an executable file, however, when I run the .exe file, it crashes with the line "import pip", and brings up (as shown below), so basically my question is: Is it possible to use CxFreeze on an application with pip imported?
Edit:
Here are all the files I am using:
setup.py (V1):
from cx_Freeze import *
import os, pip
setup(name=("ARTIST"),
version = "1",
description = "ARTIST installation file",
executables = [Executable("Install ARTIST.py"), Executable("C:\\Python34\\Lib\\site-packages\pip\\__init__.py")],
)
This brings up the error:
setup.py (V2):
from cx_Freeze import *
import os, pip
setup(name=("ARTIST"),
version = "1",
description = "ARTIST installation file",
executables = [Executable("Install ARTIST.py"],
options = {"build_exe": {"packages":[pip]}}
)
This brings up an error in the setup.bat file:
Edit:
If anyone wants to look at the website where I am publishing the larger program, here is the link:
alaricwhitehead.wix.com/artist
Edit2:
this is the error i get when i use py2exe:
Edit3:
here is a copy of the code:
https://www.dropbox.com/s/uu46iynm8fr8agu/Install%20ARTIST.txt?raw=1
please note: I didn't want to have to post a link to it, but it was too long to post directly.
The are two problems in your setup script. The first problem is that you specified extra modules to include in your frozen application under the packages option of the build_exe command: packages is for specifying which packages of your application you need to include, for the external modules (such as pip) you need to use includes. The second problem is that you need to pass to includes a list of strings of modules and not the module itself:
setup(
name=("ARTIST"),
version="1",
description="ARTIST installation file",
options={
'build_exe': {
'excludes': [], # list of modules to exclude
'includes': ['pip'], # list of extra modules to include (from your virtualenv of system path),
'packages': [], # list of packages to include in the froze executable (from your application)
},
},
executables=[
Executable(
script='run.py', # path to the entry point of your application (i.e: run.py)
targetName='ARTIST.exe', # name of the executable
)
]
)
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
I'm developing a Python application using wxPython and freezing it using cxFreeze. All seems to be going fine apart from this following bit:
When I run the executable created by cxFreeze, a blank console window pops up. I don't want to show it. Is there any way I could hide it?
It doesn't seem to be documented on the cxFreeze site and Googling didn't turn up much apart from some similar sorta problems with Py2Exe.
Thanks.
For Windows:
You have to use a line like this (use file folders and names as appropriate)
C:/Python/Scripts/cxfreeze C:/Python/Code/yourprogram.py --base-name=Win32GUI --target-dir C:/Python/Dist
By adding the --base-name=Win32GUI option, the console window will not appear.
This worked to some extent but it has issues. My program runs in both a console mode and a GUI mode. When run from the console with a --console argument it runs in a console mode. When I followed the procedure below, this doesn't work anymore and my program is only a GUI app then.
The following source code comes from a sample file in the \Python\Lib\site-packages\cx_Freeze\samples\PyQt4\setup.py. Lesson of the day. Read the README.
# A simple setup script to create an executable using PyQt4. This also
# demonstrates the method for creating a Windows executable that does not have
# an associated console.
#
# PyQt4app.py is a very simple type of PyQt4 application
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the application
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "simple_PyQt4",
version = "0.1",
description = "Sample cx_Freeze PyQt4 script",
executables = [Executable("PyQt4app.py", base = base)])
If you're using Windows, you could rename your "main" script's extension (that launches the app) to .pyw
Option 1) Use gui2exe to muck with various options.
Option 2) Modify your setup.py with 'base' parameter as such.
GUI2Exe_Target_1 = Executable(
# what to build
script = "rf_spi.py",
initScript = None,
base = 'Win32GUI', # <-- add this
targetDir = r"dist",
targetName = "rf_spi.exe",
compress = True,
copyDependentFiles = False,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = r"wireless.ico"
)