Skip to content

Instantly share code, notes, and snippets.

@zhuzhuor
Created October 31, 2013 13:53
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save zhuzhuor/7250173 to your computer and use it in GitHub Desktop.
Save zhuzhuor/7250173 to your computer and use it in GitHub Desktop.
use py2exe to generate a standalone exe file from python script
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': "my_program.py"}
],
zipfile=None,
)
shutil.move('dist\\my_program.exe', '.\\my_program.exe')
shutil.rmtree('build')
shutil.rmtree('dist')
@alimp5
Copy link

alimp5 commented Jan 22, 2016

Tnx a lot dear :x
I could do it with pyinstaller. but today, I learned a new thing :X

@M3nin0
Copy link

M3nin0 commented May 15, 2016

Very cool! Thanks

@seeamkhan
Copy link

Great! Thanks..

@karan5557
Copy link

This is great. Thanks zhuzhuor :) Cheers

@johnjohny1990
Copy link

this work just win32?

@Henrique-Miranda
Copy link

Very thanks, working using python 3.4.3 in windows 7

@imvickykumar999
Copy link

why this extra text is shown in exe file before actual execution?

Traceback (most recent call last):
  File "zipextimporter.pyc", line 88, in load_module
  File "<frozen zipimport>", line 241, in load_module
  File "<frozen zipimport>", line 721, in _get_module_code
zipimport.ZipImportError: can't find module '_ctypes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "zipextimporter.pyc", line 88, in load_module
  File "<frozen zipimport>", line 259, in load_module
  File "ctypes\__init__.pyc", line 8, in <module>
  File "zipextimporter.pyc", line 112, in load_module
ImportError: MemoryLoadLibrary failed loading _ctypes.pyd: The specified module could not be found. (126)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "boot_common.py", line 46, in <module>
  File "zipextimporter.pyc", line 121, in load_module
zipimport.ZipImportError: can't find module ctypes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment