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,
)
Related
I'm new to Python and I'm running Python 3.6. Trying to build an executable using cx_freeze and the code below in a file named "setup.py". I put the python script for the program and the icon file in the python main directory folder. When I type "python setup.py build" into the command prompt it says "running build" and then immediately generates a new command prompt. No errors are given but afterward I can't find the exe anywhere. What am I doing wrong? Am I searching for the exe files in the wrong place or is the build failing without giving an error message?
import cx_Freezefrom cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ["numpy","tkinter"], excludes = [],includes = ["numpy","tkinter"],
include_files = ["battleship.ico"])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('battleship.py', base=base)
]
setup(
name='Battleship',
version = '1.0',
description = 'A PvC Battleship Game',
options = dict(build_exe = buildOptions),
executables = executables
)
when you use py2exe
try this
import sys
try:
import py2exe
except:
raw_input('Please install py2exe first...')
sys.exit(-1)
from distutils.core import setup
import shutil
sys.argv.append('py2exe')
setup(
options={
'py2exe': {'bundle_files': 1, 'compressed': True }
},
console=[
{'script': "script.py"}
],
zipfile=None,
)
Note : remplace "script.py" with your python script and run this script like this
python exe.py
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/
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!
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,
)
i'm writing an installer using py2exe which needs to run in admin to have permission to perform various file operations. i've modified some sample code from the user_access_controls directory that comes with py2exe to create the setup file. creating/running the generated exe works fine when i run it on my own computer. however, when i try to run the exe on a computer that doesn't have python installed, i get an error saying that the import modules (shutil and os in this case) do not exist. it was my impression that py2exe automatically wraps all the file dependencies into the exe but i guess that this is not the case. py2exe does generate a zip file called library that contains all the python modules but apparently they are not used by the generated exe. basically my question is how do i get the imports to be included in the exe generated by py2exe. perhaps modification need to be made to my setup.py file - the code for this is as follows:
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
)
Try to set options={'py2exe': {'bundle_files': 1}}, and zipfile = None in setup section. Python will make single .exe file without dependencies. Example:
from distutils.core import setup
import py2exe
setup(
console=['watt.py'],
options={'py2exe': {'bundle_files': 1}},
zipfile = None
)
I rewrite your setup script for you. This will work
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
#the options is what you fail to include it will instruct py2exe to include these modules explicitly
options={"py2exe":
{"includes": ["sip","os","shutil"]}
}
)