Process to convert simple Python script into Windo

2020-01-23 15:06发布

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:

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.

8条回答
混吃等死
2楼-- · 2020-01-23 16:03

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

查看更多
爷的心禁止访问
3楼-- · 2020-01-23 16:03

1) Get py2exe from here, according to your Python version.

2) Make a file called "setup.py" in the same folder as the script you want to convert, having the following code:

from distutils.core import setup
import py2exe
setup(console=['myscript.py']) #change 'myscript' to your script

3) Go to command prompt, navigate to that folder, and type:

python setup.py py2exe

4) It will generate a "dist" folder in the same folder as the script. This folder contains the .exe file.

查看更多
登录 后发表回答