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:33

I also recommend pyinstaller for better backward compatibility such as python 2.3 - 2.7.
for py2exe, you have to have python 2.6

查看更多
千与千寻千般痛.
3楼-- · 2018-12-31 02:33

py2exe will make the exe file you want but you need to have the same version of MSVCR90.dll on the machine you're going to use your new exe. See http://www.py2exe.org/index.cgi/Tutorial for more info.

查看更多
初与友歌
4楼-- · 2018-12-31 02:34

I'm told that PyRun, https://www.egenix.com/products/python/PyRun/, is also an option.

查看更多
墨雨无痕
5楼-- · 2018-12-31 02:36

Use Cython to convert to c, compile and link with gcc. Another could be, make the core functions in c (the ones you want to make hard to reverse), compile them and use python boost to import the compiled code ( plus you get a much faster code execution). then use any tool mentioned to distribute.

查看更多
时光乱了年华
6楼-- · 2018-12-31 02:37

Yes, it is possible to compile Python scripts into standalone executable.

PyInstaller can be used to convert Python programs into stand-alone executables, under Windows, Linux, Mac OS X, FreeBSD, Solaris and AIX. It is one of the recommended converters.

py2exe converts Python scripts into only executable in Windows platform.

Cython is a static compiler for both the Python programming language and the extended Cython programming language.

查看更多
牵手、夕阳
7楼-- · 2018-12-31 02:41

I would like to compile some useful information about creating standalone files on windows using Python 2.7.

I have used py2exe and it works, but I had some problems.

This last reason made me try PyInstaller http://www.pyinstaller.org/ .

In my opinion, it is much better because:

  • It is easier to use.

I suggest creating a .bat file with the following lines for example (pyinstaller.exe must be in Windows Path):

pyinstaller.exe --onefile MyCode.py

So, I think that, at least for python 2.7, a better and simpler option is PyInstaller.

查看更多
登录 后发表回答