How to compile python script to binary executable
I need to convert a Python script to a Windows executable.
I have Python 2.6 installed to
I have created one script and kept it in
C:\pythonscript. Inside this folder there are two files
oldlogs.py (this file need coversion)
setup.py code is
from distutils.core import setup import py2exe setup(console=['oldlogs.py'])
How can I convert oldlogs.py to an exe file?
Here is how one could fairly easily use PyInstaller to solve the issue at hand:
From the tool's documentation:
PyInstaller analyzes myscript.py and:
- Writes myscript.spec in the same folder as the script.
- Creates a folder build in the same folder as the script if it does not exist.
- Writes some log files and working files in the build folder.
- Creates a folder dist in the same folder as the script if it does not exist.
- Writes the myscript executable folder in the dist folder.
In the dist folder you find the bundled app you distribute to your users.
Read more... Read less...
I recommend PyInstaller, a simple python script can be converted to an exe with the following commands:
utils/Makespec.py [--onefile] oldlogs.py
which creates a yourprogram.spec file which is a configuration for building the final exe. Next command builds the exe from the configuration file:
More can be found here
# -*- mode: python -*- block_cipher = None a = Analysis(['SCRIPT.py'], pathex=[ 'folder path', 'C:\\Windows\\WinSxS\\x86_microsoft-windows-m..namespace-downlevel_31bf3856ad364e35_10.0.17134.1_none_50c6cb8431e7428f', 'C:\\Windows\\WinSxS\\x86_microsoft-windows-m..namespace-downlevel_31bf3856ad364e35_10.0.17134.1_none_c4f50889467f081d' ], binaries=[(''C:\\Users\\chromedriver.exe'')], datas=, hiddenimports=, hookspath=, runtime_hooks=, excludes=, win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name='NAME OF YOUR EXE', debug=False, strip=False, upx=True, runtime_tmpdir=None, console=True )