.exe made using py2exe not doing anything - python

I'm using Python 2.7.9 on Windows 7 x86
the file i'm trying to make into an executable has the following source code:
import Tkinter
root=Tkinter.Tk()
root.mainloop()
Yeah, not much, just an empty window.
The setup file is:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
s=raw_input("Name:")
s=s+".py"
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{'script': s}],
zipfile = None,
)
When i run the exe, nothing happens, even when using cmd. I get no errors either, it just... does nothing.

I've always found cx_freeze easier to use on Windows
http://cx-freeze.sourceforge.net/

Related

Cannot run generated .exe with py2exe

I am trying to generate aa .exe using py2exe for a python script that generates an excel. Here is just a sample code. I am writing value 100 to a cell and saving the excel to Users Desktop using openpyxl. This works perfectly fine when I run it directly.
import openpyxl
import getpass
wb = openpyxl.Workbook()
ws = wb.create_sheet('test')
ws.cell(row=1, column=1, value=100)
username = getpass.getuser()
wb.save('C:\\Users\\{}\\create_exe\\gen.xlsx'.format(username))
print 'Done'
And when I compile it using py2exe it compiles also just fine.
The problem arises when I run the generated .exe file. I get a return saying
ImportError: No module named jdcal
setup.py file is as follows
import py2exe
from distutils.core import setup
packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml"]
excludes = []
setup(console=['test_program.py'],
options={"py2exe": {"excludes": excludes,
"packages": packages}}
)
Thisngs I have already tried
I have searched and few people said Install openpyxl using pip. I
have done that and pip says its alöready installed.
I have also tried to install jdcal using pip and pip says it is installed.
I have uninstalled jdcal and installed it using pip and manually, and
still the same error.
I have included jdcal in the packages and still no change in the outcome.
I hope someone can help me with it.
Thanks in advance
EDIT :
Generated Filed in dist folder are as follows (openpyxl cannot be seen here, I don't know why)
tcl (Folder)
_ctypes.pyd
_elementtree.pyd
_hashlib.pyd
_multiprocessing.pyd
_socket.pyd
_ssl.pyd
_tkinter.pyd
bz2.pyd
pyexpat.pyd
select.pyd
unicodedata.pyd
win32ui.pyd
numpy.core._dummy.pyd
numpy.core.multiarray.pyd
numpy.core.multiarray_tests.pyd
numpy.core.operand_flag_tests.pyd
numpy.core.struct_ufunc_test.pyd
numpy.core.test_rational.pyd
numpy.core.umath.pyd
numpy.core.umath_tests.pyd
numpy.fft.fftpack_lite.pyd
numpy.linalg._umath_linalg.pyd
numpy.linalg.lapack_lite.pyd
numpy.random.mtrand.pyd
_win32sysloader.pyd
win32api.pyd
win32pdh.pyd
win32pipe.pyd
tk85.dll
tcl85.dll
libiomp5md.dll
pywintypes27.dll
python27.dll
w9xpopen.exe
pythoncom27.dll
library.zip
test_program.exe (Executable File)
Try to manually include it in setup.py in packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml"]
so it would be:
packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml", "jdcal"]
I personally have had good luck letting py2exe detect the modules that are needed. I've never tried to specify every module necessary.
try this:
from distutils.core import setup
import py2exe
setup(console=['test_program.py'])
this should be run from command line as
python setup.py py2exe
py2exe outputs .dll files in the dist directory, these have to be in the directory that you run your .exe file from. if you just want one .exe file and no .dll files try this:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
console = [{'script': "test_program.py"}],
zipfile = None,
)
this should be run from command line as
python setup.py
I use cx_freeze and never had any issues.
Here's the setup.py for a cx_freeze file
from cx_Freeze import setup, Executable
build_exe_options = {"excludes": ["html5lib"],"optimize":2}
setup(name = "App Name" ,
version = "1.0.0.0" ,
options = {"build_exe": build_exe_options},
description = "" ,
executables = [Executable("FooBar.py")])

Python: PYInstaller, CX_Freeze: Cannot create installer

I built a python app, and I'm using Ubuntu 16.04 and python 2.7.
I'm trying to compile the python script as .EXE to work on windows but I cannot find a way to make it start. I'm also having Selenium and Tkinter in my script.
Here's what my python file looks like:
import ast
import random
import thread
import time
import tkMessageBox
from Tkinter import *
import os
from selenium import webdriver
from selenium.webdriver import ActionChains
global geckodriver
if os.name == 'nt':
geckodriver = "./geckodriver.exe"
else:
geckodriver = "./geckodriver"
I'm also using a PNG file as tkinter icon and displayed picture in Tkinter:
photo = PhotoImage(file="smallblack.png")
root.tk.call('wm', 'iconphoto', root._w, photo)
w = Label(root, image=photo)
w.photo = photo
w.pack(side=TOP, pady=15)
and also using two text files for the script to read later:
def countlinks():
lines = 0
for line in open("checklinks.txt"):
lines += 1
return lines
but I thought this can be added later next to the generated .exe.
Now, here is my setup.py used by cx_freeze:
#setup.py
from cx_Freeze import setup, Executable
setup(
name = "MainExe",
version = "1.0.0",
options = {"build_exe": {
'packages': ["ast","random","thread","time", "tkMessageBox", "Tkinter", "os", "selenium"],
'include_files': ['smallblack.png','geckodriver','geckodriver.exe'],
'include_msvcr': True,
}},
executables = [Executable("main.py)]
)
What am I doing wrong? When building the .exe with pyinstaller (pyinstaller main.py --onefile), the .exe builds but it doesn't open in Windows (opens a console window for 1 second and closes it), and if I'm trying to run it in CMD it says the program is too big.
When trying to run cx_freeze (python setup.py build) it creates a .exe that will only open a console and nothing else happens.
I've been googling this for the last 5 hours with no success.
What am I doing wrong?
In the example of CX_Freeze, this is happening most likely because your build is missing one of the packages it requires. The reason it is opening the console window is because you didn't set the base to "Win32GUI". Once you do this, you'll get a dialog box which shows the error message and you can include that package in your "include" list.
Try:
#setup.py
from cx_Freeze import setup, Executable
setup(
name = "MainExe",
version = "1.0.0",
options = {"build_exe": {
'packages': ["ast","random","thread","time", "tkMessageBox", "Tkinter","os", "selenium"],
'include_files': ['smallblack.png','geckodriver','geckodriver.exe'],
'include_msvcr': True,
}},
executables = [Executable("main.py", base="Win32GUI")]
)

Py2Exe generate log file

My problem is that py2exe is generating a log file when I run. It doesn't generate because I have an error when running the program. At the log file there is the standard console print out!
How can I do it that no log file would generate?
here my py2exe setup code:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{'script': "run.py"}],
zipfile = None
)
In GUI applications, Py2exe redirects sys.stderr to a log file and sys.stdout to an object that ignores all writes. To avoid the log file, do this in your program at the top of the main module:
import sys
sys.stderr = sys.stdout
Or, let py2exe create a console application by using the console keyword instead of windows in setup.py.
Probably you can remove the content of the file! It can work, but you must see if your programm needs some function defined there and then it can get errors!
At the chat you said that you want to use Python 3 but Py2Exe isn't there... Why don't you use cx_Freeze? It generates a bin and an .exe file. You can make an Installation with InnoSetup and you Game is perfect!

Print not working when compiled with py2exe

this is my very simple code, printing argvs:
import sys
argv=sys.argv
for each in sys.argv:
print each
here's the output when ran:
e:\python>python test1.py 1 2 3 4 5
test1.py
1
2
3
4
5
I want it to be compiled, so I made one with py2exe:
e:\python>python setup.py py2exe
and my setup.py:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 3}},
windows = [{'script': "test1.py"}],
zipfile = None,
)
and I don't get any output when I run my program by test1.exe 1 2 3 4 5 or with any other argvs. sys.argvs should be a list with at least one object(test1.exe) in it, therefore I think I have misunderstandings with print function of python.
Is there anything I'm doing wrong here? I just want everything to be printed to commandline. I program from linux, but windows users should be using my program.
thank you very much
# ...
windows = [{'script': "test1.py"}],
#...
windows option is used to create GUI executables, which suppresses console output. Use console instead:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 3}},
console = [{'script': "test1.py"}],
zipfile = None,
)

Best of both worlds: python packaging for a game

I am currently trying to package a game made with python and pygame and I am running into some issues.
I am using py2exe to package and have looked up some question on here about it but I couldn't find a great solution. I want to end up with a folder, containing an exe, that I can compress and put online. Running the setup.py works fine except it puts all the dependencies into library.zip. This means that the program, when run, does not work.
I found that someone else was running into this issue and they ended using the "skip archive = true" option to solve it. And while, yes, that does work for me too I was hoping there was a method that would still let the program be run without trouble but wouldn't clutter the folder with countless files.
To be very precise the issue I'm running into with the library.zip is:
ImportError: MemoryLoadLibrary failed loading pygame\mixer.pyd
Which, if I understand it properly, means that the program can not reach/find the mixer module of Pygame.
Here is the setup script I am currently using (and that isn't working):
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
data_files = [('resources', ['resources/step.wav',
'resources/wind2.wav',
'resources/The Steppes.ogg',
'resources/warrior3-nosword-notassle.png',
'resources/warrior3-sword.png',
'resources/warrior2-blood1.png',
'resources/warrior2-blood2.png',
'resources/warrior2-blood3.png',
'resources/warrior2-blood4.png',
'resources/warrior3-up.png',
'resources/warrior3-kneel.png',
'resources/warrior3-kneel-nosword.png',
'resources/warrior2-blood2-kneel.png',
'resources/warrior2-blood3-kneel.png',
'resources/warrior2-blood4-kneel.png',
'resources/warrior3-death.png',
'resources/warrior3-offarm.png',
'resources/menu1.png',
'resources/plains3-top-nomount.png',
'resources/mountains.png',
'resources/plains5-bottom.png',
'resources/plains3-bottom.png',
'resources/cloud1.png',
'resources/warrior2-sword.png',
'resources/warrior2-hand.png',
'resources/blue-tassle1.png',
'resources/blue-tassle2.png',
'resources/blue-tassle3.png',
'resources/blue-tassle4.png'])]
setup(options = {'py2exe': {"bundle_files": 1}},
data_files = data_files,
console = [{'script': "steppes2.0.py"}],
zipfile = None
)
This code in your setup.py should do the trick of producing a single executable (you will still have to distribute msvc dlls separately)
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
console = [{'script': "myscript.py"}],
zipfile = None,
)

Categories