Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process to convert simple Python script into Windows executable [duplicate]

I wrote a script that will help a Windows user in her daily life. I want to simply send her the .exe and not ask her to install python, dlls or have to deal with any additional files.

I've read plenty of the stackoverflow entries regarding compiling Python scripts into executable files. I am a bit confused as there are many options but some seem dated (no updates since 2008) and none were simple enough for me not to be asking this right now after a few hours spent on this.

I'm hoping there's a better, up-to-date way to do this.

I looked into:

  • pylunch
  • py2exe
  • cx_Freeze
  • py2app (only for Mac)
  • pyinstaller
  • bbfreeze

but either I couldn't get them to work or couldn't understand how to get the result I need. The closest I got was with py2exe but it still gave me the MSVCR71.dll

I would appreciate a step-by-step answer as I was also unable to follow some of the tweaking answers here that require some prior understanding of how to use py2exe or some of the other tools.

I'm using Python 2.5 as one of the modules is only available for that version.

like image 648
greye Avatar asked Jan 26 '10 00:01

greye


People also ask

Can you convert Python script to exe?

Using pyinstaller you can convert the python file to exe. Type pyinstaller <python-file-name>, this will convert the . py to .exe file with console. Add –no-console keyword after pyinstaller to convert python file to executable without command prompt.

What tool can convert Python script to Windows executable?

You can just type pip install pyinstaller to install it and pyinstaller -w yourpythonscript.py to compile it to an exe.

How do I automatically convert py to exe?

First visit the GitHub page for this library and download the code using the download ZIP option as shown in the image below. Next extract the file, locate the python file called run.py and execute it. This should open up the interface for auto-py-to-exe.


2 Answers

PyInstaller will create a single-file executable if you use the --onefile option (though what it actually does is extracts then runs itself).

There's a simple PyInstaller tutorial here. If you have any questions about using it, please post them...

like image 83
Nicholas Riley Avatar answered Sep 18 '22 10:09

Nicholas Riley


Using py2exe, include this in your setup.py:

from distutils.core import setup import py2exe, sys, os  sys.argv.append('py2exe')  setup(     options = {'py2exe': {'bundle_files': 1}},     windows = [{'script': "YourScript.py"}],     zipfile = None, ) 

then you can run it through command prompt / Idle, both works for me. Hope it helps

like image 37
PPTim Avatar answered Sep 17 '22 10:09

PPTim