How To add icons to exe using Cx_Freeeze - python

I havs the setup.py file which is used to build my program. I wanted to know how to add an icon to the final exe
import sys
from cx_Freeze import setup, Executable
setup(
name = "Calculator",
version = "3.7.8",
description = "Simple Calculator",
executables = [Executable("Calculator.py", base = "Win32GUI")])

Just add icon=icon.ico in Executable() like this:
from cx_Freeze import setup, Executable
target = Executable(
script="Calculator.py",
base="Win32GUI",
compress=False,
copyDependentFiles=True,
appendScriptToExe=True,
appendScriptToLibrary=False,
icon="icon.ico"
)
setup(
name="Calculator",
version="3.7.8",
description="Simple Calculator",
author="Hanzalah Ravat",
options={"build_exe": options},
executables=[target]
)

Related

cx_Freeze EXE application doesn't works on other computer

I want to change a python script into an executable file.
The compilation is proceeding correctly and the executable works correctly on my computer.
The problem is that when I export the exe.win32-3.8 directory to another computer, the executable doesn't works. The execution window opens and closes immediately. The IE windows doesn't opens.
here is my setup.py :
from cx_Freeze import setup, Executable
# On appelle la fonction setup
setup(
name = "CampaignRecovery",
version = "0.1",
description = "Ce programme recupère les campagnes depuis Opoci",
executables = [Executable("CampaignRecovery.py")],
)
And my source code :
from selenium import webdriver
from selenium.webdriver.ie.options import Options
ieOptions = Options()
ieOptions.ignore_protected_mode_settings = True
browser = webdriver.Ie(options=ieOptions)
Could you, please help me ?
Regards
This is my setup. not guarantee gonna work on your case, just to make sure you have python installed on target machine for testing purposes. and run it through CMD. from CMD you will able to tell what's wrong
import cx_Freeze
import sys
import os
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
print(os.environ['TCL_LIBRARY'],os.environ['TK_LIBRARY'])
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
syspath = r"C:\Python\DLLs"
buildOptions = dict(
packages=["tkinter","pandas","numpy"],
excludes=[],
include_files=[('tcl86t.dll', os.path.join('lib', 'tcl86t.dll')),('tk86t.dll', os.path.join('lib', 'tk86t.dll'))]
)
executables = [cx_Freeze.Executable("[YOUR APP].py", base=base, icon="hitek.ico")]
cx_Freeze.setup(
name = "YOUR APP",
options = dict(build_exe=buildOptions),
version = "0.02",
description = "YOUR APP",
executables = executables
)

Python 3.6 After converting tkinter to exe - SSH function stopped working

After I did the convert to exe, ssh(paramiko) function does not work anymore. It does not connect to the device.
I have included paramiko and socket packages. Any Idea?
it is working in with non-converted version.
setup.py file
import cx_Freeze
from cx_Freeze import setup, Executable
import os
import sys
includes = []
include_files = ["C:\\Python36-32\DLLs\\tcl86t.dll",
"C:\\Python36-32\DLLs\\tk86t.dll",
"C:\\Gustavo\\PyCharmPortable\\new\\cpass.ico",
"C:\\Gustavo\\PyCharmPortable\\new\\py2.py",
"C:\\Gustavo\\PyCharmPortable\\new\\py3.py",
"C:\\Gustavo\\PyCharmPortable\\new\\tn.py",
"C:\\Gustavo\\PyCharmPortable\\new\\file1.csv"]
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = "C:\\Python36-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Python36-32\\tcl\\tk8.6"
base = 'Win32GUI' if sys.platform == 'win32' else None
setup(name='Password Change', version='0.1', description='Password Change',
options={"build_exe": {"packages": ["tkinter","paramiko","PIL","socket","telnetlib"], "includes": includes, "include_files": include_files}},
executables=[Executable('cp.py', base=base)])
try including the socket.py/socketserver.py and the _multiprocessing.pyd/_tkinter.pyd/_socket.pyd, this is what worked for me.
include_files = [
"C:\\Python36-32\DLLs\\tcl86t.dll",
"C:\\Python36-32\DLLs\\tk86t.dll",
"Python36/Lib/socket.py",
"Python36/Lib/socketserver.py",
"Python36/DLLs/_multiprocessing.pyd",
"Python36/DLLs/_tkinter.pyd",
"Python36/DLLs/_socket.pyd",
"C:\\Gustavo\\PyCharmPortable\\new\\cpass.ico",
"C:\\Gustavo\\PyCharmPortable\\new\\py2.py",
"C:\\Gustavo\\PyCharmPortable\\new\\py3.py",
"C:\\Gustavo\\PyCharmPortable\\new\\tn.py",
"C:\\Gustavo\\PyCharmPortable\\new\\file1.csv",

Problems with Cx_freeze

If I'm actually asking you for help, it's because I spend many hours for nothing into trying to fix my problem:
I would like to compile my python script into .exe:
(I am using Python 32 bits 3.1.4 and pygame)
I have 4 files: Class.pyc, _Class_game.pyc, _ressources.pyc et main.py
and a folder #ressources with all images and songs
This is my scritp setup.py:
import cx_Freeze
executables = [cx_Freeze.Executable("main.py"), base = "Win32GUI"]
cx_Freeze.setup(
name="Strike The square",
version = "2.0",
description = "Jeu Strike The Square, V2.1",
options={"build_exe": {"packages":["pygame"],
"include_files": ["_Class_.pyc","_Class_game.pyc","_ressources.pyc"]}},
executables = executables
)
This create a folder "exe.xin32-3.1" with python (compiled) and my game
Next, I use inno setup to build the installer and add the folder #ressources
On my computer, It works very well, but when one of my friend wants to play (he hasn't python and pygame), the game creates this error:
[Error][1]
Then...I think this error comes from windows' ressources but I don't know how can I fix it...
The option (in setup.py):
include_msvcr = True
Doesn't work...
Thanks for your answer and excuse my english...
Hawk_Eyes
PS: this my game imports
try:
import pygame,time, ctypes
from random import randint
from pygame.locals import *
from math import sqrt
from _ressources import Shared
except ImportError as e:
print("Erreur du chargement du module: {0}".format(e))
Not sure if this will help but this is a copy of my setup file, i have used this to compile Pygame, Pubnub and various things. notice i don't include the files i want to include. The setup auto finds the files needed.
import sys
from cx_Freeze import setup, Executable
exe = Executable(
script = r"launcher.py",
base = 'Win32GUI',
icon = None,
targetName = "launcher.exe"
)
setup(
version = "0.1",
description = "launcher",
author = "Joshua Nixon",
name = "launcher",
executables = [exe]
)
$ cd path/to/files
$ python file.py build
EDIT
I recently found you could create .MSI files using cx_freeze which are very nice for distributing. IF the program uses images then (because you cannot bundle images with the MSI (that i know of) you create a little function which downloads them on launch from imgur or some place))
setup.py for MSI
import sys
from cx_Freeze import setup, Executable
company_name = "JoshuaNixon"
product_name = "Test"
bdist_msi_options = {
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s' % (company_name),
}
if sys.platform == 'win32':
base = 'Win32GUI'
else:
base = None
exe = Executable(script='launcher.py',
base=base,
icon="mushroom.ico",
)
setup(name=product_name,
version='1.0.0',
description='blah',
executables=[exe],
options={'bdist_msi': bdist_msi_options})
$ cd path/to/files
$ python file.py bdist_msi

Run time error with twisted and cx_freeze

I am currently trying to freeze some python code using twisted with cx_freeze.
I have this in my python file Main.py :
print('Start')
import twisted.internet
input('End')
and this in setup.py file :
import sys
from cx_Freeze import setup, Executable
includes = ["twisted.internet", "twisted.internet.protocol", "pkg_resources"]
excludes = []
packages = []
namespace_packages = ["zope"]
build_exe_options = {"packages": packages, "excludes": excludes, "includes": includes, "namespace_packages": namespace_packages, "append_script_to_exe":True}
base = None
#if sys.platform == "win32":
# base = "Win32GUI"
setup( name = "xxx",
version = "1.0",
author = "xxx",
author_email = "xxx",
description = "xxx",
options = {"build_exe": build_exe_options},
executables = [Executable("Main.py", base=base, icon = None)])
I keep getting a run time error R6034 when I run my compiled program. Someone knows why ?
In the end, I used a workaround. I figured out that the file zope.interface._zope_interface_coptimizations was the root of the issue (it fails to load) so I excluded it in my setup.py file :
excludes = ["zope.interface._zope_interface_coptimizations"]
It now works well but the initial problem is not solved and I fear I would need this package at some point.

Using CX_Freeze with Scipy: scipy.special._ufuncs.py

I am having problems freezing a programm of mine. I narrowed it down to the scipy module. The porgramm I am trying to freeze is:
from scipy import signal
signal.hann(1000)
My setup script is:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "Some name",
version = "1.0",
author="My name",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("Script_Name.py", base=base)])
# ^CHANGE THIS NAME!!!
Here is a picture of the error message. I also tried including scipy.signal in the setup file as
build_exe_options = {"includes":"scipy.signal"}
but it didn't do any good. Please help me.
I had a similar problem which could be solved by making sure that:
1 The build directory contains a file named _ufunc.pyd (instead of scipy.special._ufuncs.pyd as mentioned above). You can achieve this by specifying the build_exe_options:
build_exe_options = { 'packages': ['scipy'],
"include_files": [('path2python\\Lib\\site-packages\\scipy\\special\\_ufuncs.pyd','_ufuncs.pyd')]}
2 Making sure that all dlls used by ufunc.pyd are also in the build directory. In my case libifcoremd.dll adn libmmd.dll were failing. You can check this with dependencywalker
I hope this helps you out.

Categories

Resources