Adding an icon in an exe through py2exe - python-2.7

I am making an exe through py2exe using a python script.
I had already gone through many examples of setup.py but none is working. I am using windows 7 64 bit and python 2.7.
from distutils.core import setup
import py2exe
import time
setup(
windows = [
{
"script": "myapp.py",
"icon_resources": [(1, "Windows.ico")]
}
],
)
time.sleep(2)
But dist produced through this setup.py contains myapp.exe with default exe image, not the icon I included. In cmd I am using python stup.py py2exe

I use py2exe through gui2exe and never had a problem with icon.
With gui2exe, you don't have to write setup.py and works great with py2exe, cx_freeze, etc.
You can get it here http://code.google.com/p/gui2exe/
And just start gui2exe.py by double clicking it (no installation required).

Related

1.py script convertd to exe using cx_Freeze not working on windows

I have written a basic python gui.
from Tkinter import *
root = Tk(className ="My first GUI")
foo = Label(root,text="Hello World")
foo.pack()
root.mainloop()
Now I want that this .py script runs on windows systems without python as well. I used cx_freeze module for this and created a setup.py file like this
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["Tkinter"], "excludes": []}
base = None
if sys.platform == "win64":
base = "Win64GUI"
setup( name = "guiDemo",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("guiDemo.py", base=base)])
I am running this script as
python setup.py build
The output build directory as a exe file but when copy the whole folder and run it on a Windows system (Win 8.1 pro mainly) I see this
Win 8.1 pro
Also ran it on ubuntu using Wine and got this -
wine: Bad EXE format
What am I doing wrong ?
Using ubuntu 14.04

py2exe fails to resolve ibm_db dependency (DLL)

I am trying to create an EXE using py2exe for a desktop app I wrote with python 2.7.
The app utilizes ibm_db (v2.0.7), which installs to site-packages as an .egg folder.
The contents of the ibm_db.py file are very short, as the logic itself is implemented in the DLL:
import os
if 'clidriver' not in os.environ['PATH']:
os.environ['PATH'] = os.environ['PATH'] + ";" + os.path.join(os.path.abspath(os.path.dirname(__file__)), 'clidriver', 'bin')
def __bootstrap__():
global __bootstrap__, __loader__, __file__
import sys, pkg_resources, imp
__file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\ibm_db.dll')
__loader__ = None; del __bootstrap__, __loader__
imp.load_dynamic(__name__,__file__)
__bootstrap__()
When I ran py2exe on the project, the dependency on ibm_db wasn’t properly handled (the DLL wasn’t taken into the dist), so running the exe file stumbles upon the following error:
...
File "ibm_db.pyc", line 10, in <module>
File "ibm_db.pyc", line 6, in __bootstrap__
ImportError: No module named pkg_resources
I tried to copy the DLL manually into the dist folder (both directly and under ibm_db_dlls subfolder), but it’s of no use.
I found this page, and realized that py2exe has an issue with eggs:
http://www.py2exe.org/index.cgi/ExeWithEggs
As far as I understand, unzipping the egg is not the way to go in my case, because my program does use pkg_resources (through ibm_db.py). Still, I tried installing ibm_db via easy_setup with the --always-unzip option, but the installation gave me this error:
Not a URL, existing file, or requirement spec: '--always-unzip'
and it was still installed as an .egg.
So I’m looking at the “Including .egg files in your dist directory” option, and wondering whether it can help. And if so – where to start?
I’m using this simple setup.py for running py2exe:
from distutils.core import setup
import py2exe
setup(console=['MyApp.py'])
What is this “TurboGears” mentioned there? It doesn’t look like something I’m using in my app.
Any advice will be appreciated.
Thanks.

Pyinstaller with Tkinter Matplotlib numpy scipy

I am using Pyinstaller (after spending a long time with py2exe) to convert my REAL.py file to .exe. I used Anaconda to make .py file which is running perfectly on my computer. But when I make .exe file, it shows no error and an application is created in dist\REAL folder. But when I run the .exe file, the console opens and closes instantly.
It should ideally show a GUI window and take inputs and use them to make plots. It does so when I run REAL.py file. I am using Tkinter, Matplotlib, numpy, scipy which comes with Anaconda.
EDIT: I tried to run simple code to check the compatibility with matplotlib:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
The same issue persists with this. Opens console window and then closes but no plot is given out.
I found the solution in py2exe. Following was the setup.py file that worked with Tkinter Matplotlib numpy scipy imports:
from distutils.core import setup
import py2exe
from distutils.filelist import findall
import matplotlib
opts = {"py2exe": {
"packages" : ['matplotlib'],
"includes": ['scipy', 'scipy.integrate', 'scipy.special.*','scipy.linalg.*'],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll']
}
}
setup(
windows = [{'script': "with_GUI.py"}], zipfile = None,
options= opts,
data_files = matplotlib.get_py2exe_datafiles()
)
But this gave me some error saying that there was version conflict with two files. So I changed the two files viz. dist/tcl/tcl8.5/init.tcl (in line 19) and dist/tcl/tk8.5/tk.tcl (in line 18). In my case I changed the version from 8.5.15 to 8.5.18. I found the location of the two files by looking at the path specified by the error in error log. Then the .exe worked just fine.
I hope this helps.
Try using the --hidden-import=matplotlib when calling pyinstaller. For example, in the command prompt you would type:
Pyinstaller --hidden-import=matplotlib your_filename_here.py
and you could try giving it a shot with tkinter in there as well.
Pyinstaller --hidden-import=matplotlib --hidden-import=tkinter your_filename_here.py

I have created exe file using py2exe, I Need to bundle all dependency files into single exe to improve portability.How canI do that?

I have created .exe file using py2exe, I Need to bundle all dependency files into single exe to improve portability.
How can I do that ? Thanks in advance.
I have tried this code:
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': 1}},
zipfile = None,
console = [{'script': script_file}]
)
But library.zip file & w9xpopen.exe files are still existing in the dist folder, while generating .exe I am getting following warning:
unknown distribution option Zipfile while using py2exe.
Is this this reason why all the files are not included in my exe??
I am doing this in:
Windows 7 32 bit.
Python version 2.7.3
py2exe version 0.6.9.
i use this:
options = {'py2exe': {
'compressed':1,
'bundle_files': 2,
'dist_dir': "my/dist/dir"
}}
setup(console=['main.py'], options=options)
and it has always worked out as it should
when typing in console C:\python27> python setup.py py2exe

py2exe can't find msvcp90.dll

I'm working on converting a simple GUI script written with Python 2.7 and Pyqt4 into a standalone executable using py2exe. I keep getting "no such file exists" errors, and I've managed to fix a few, though this one seems stubborn. It can't find msvcp90.dll, and returns an error message with a short traceback to distutils and then back to my py2exe script, which isn't very enlightening.
I've installed the MS C++ redistributable runtime, as recommended in
py2exe fails to generate an executable
but my script still can't locate the .dll. Below is my py2exe script, with the name of my script blocked out:
from distutils.core import setup
from py2exe.build_exe import py2exe
import sys, os, zmq
sys.argv.append('py2exe')
os.environ["PATH"] = \
os.environ["PATH"] + \
os.path.pathsep + os.path.split(zmq.__file__)[0]
setup(
options = {'py2exe':{'bundle_files':1,"includes":["zmq.utils",
"zmq.utils.jsonapi","zmq.utils.strtypes"]}},
console = [{'script':"#######.py"}],
zipfile = None
)
I've already fixed an issue with zmq (which isn't ever used by my script, or my GUI, for that matter, as far as I know). What am I doing wrong?
Right, I've managed to get my app to build, and although the question is now moderately old, it's my hope this is eventually of use to someone.
Firstly, py2exe is probably the wrong tool. It's old and AFAICT unmaintained. Consider PyInstaller instead. Using PyInstaller is literally as simple as installing it, installing PyWin32, and then going python %path_to_pyinstaller%/pyinstaller.py --onefile --windowed source.py. PyInstaller deals with all the mess of side by side assemblies and so on without you having to do anything.
In short, use PyInstaller.
However, to answer your question, this worked for me:
The question you've linked to - in particular this answer is the right start. Find the right DLLs and copy them to C:\Python27\DLLs
Ditch your existing setup.py file. If you're not using zmq, there's no reason to import it. Also, for a windowed application you want windows= not console=. My file goes (for packaging show.py):
#!/usr/bin/python
from distutils.core import setup
import py2exe
setup(options={'py2exe':{'bundle_files':1}},
windows=['show.py'])
(This is pinched off http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/)