How to make a Python script standalone executable

2018-12-31 01:43发布

I'm building a Python application and don't want to force my clients to install Python and modules. I also want to make my application closed-source.

So, is there a way to compile Python scripts to standalone executables?

16条回答
公子世无双
2楼-- · 2018-12-31 02:20

Use py2exe.... use below set up files:

 from distutils.core import setup
 import py2exe

 from distutils.filelist import findall
 import matplotlib

 setup(
       console=['PlotMemInfo.py'],

       options={
                'py2exe': {
                'packages' : ['matplotlib'],
            'dll_excludes': ['libgdk-win32-2.0-0.dll',
                                 'libgobject-2.0-0.dll',
                 'libgdk_pixbuf-2.0-0.dll']
                          }
                },
       data_files = matplotlib.get_py2exe_datafiles()
     )
查看更多
人气声优
3楼-- · 2018-12-31 02:21

For Python 3.2 scripts the only choice is Cxfreeze. Build it from sources otherwise it won't work.

For python 2.x I suggest pyinstaller as it can package a python program in a single executable, unlike CxFreeze which outputs also libraries.

查看更多
残风、尘缘若梦
4楼-- · 2018-12-31 02:22

You can find the list of distribution utilities listed @ https://wiki.python.org/moin/DistributionUtilities.

I use bbfreeze and it has been working very well (yet to have python 3 support though).

查看更多
零度萤火
5楼-- · 2018-12-31 02:32

you may like py2exe. you'll also find in there infos for doing it on linux

查看更多
看风景的人
6楼-- · 2018-12-31 02:33

You can use py2exe as already answered and use cython to convert your key .py files in .pyc, C compiled files, like .dll in Windows and .so in linux, much harder to revert than common .pyo and .pyc files (and also gain in performance!)

查看更多
人间绝色
7楼-- · 2018-12-31 02:33

And a third option is cx_Freeze, which is cross-platform.

查看更多
登录 后发表回答