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!)
You might wish to investigate Nuitka. It takes python source code and converts it in to C++ API calls. Then it compiles into an executable binary (ELF on Linux). It has been around for a few years now and supports a wide range of Python versions.
You will probably also get a performance improvement if you use it. Recommended.
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.
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.
Not exactly a packaging of the python code, but there is now also grumpy from google, which transpiles the code to Go. It doesn’t support the python C api, so it may not work for all projects.
Using pyinstaller, I found a better method using shortcut to the .exe rather than making --onefile. Anyways there’s probably some data files around and if you’re running a site-based app then your program depends on html, js, css files too. No point in moving all these files somewhere.. instead what if we move the working path up.
Make a shortcut to the exe, move it at top and set the target and start-in paths as specified, to have relative paths going to dist\folder:
Target: %windir%\system32\cmd.exe /c start dist\web_wrapper\web_wrapper.exe
Start in: "%windir%\system32\cmd.exe /c start dist\web_wrapper\"
Can rename shortcut to anything so renaming to “GTFS-Manager”
Now when I double-click the shortcut, it’s as if I python-ran the file! I found this approach better than the --onefile one as:
In onefile’s case, there’s a problem with a .dll missing for win7 OS which needs some prior installation etc. Yawn. With the usual build with multiple files, no such issues.
All the files that my python script uses (it’s deploying a tornado web server and needs a whole freakin’ website worth of files to be there!) don’t need to be moved anywhere: I simply create the shortcut at top.
I can actually use this exact same folder in ubuntu (run python3 myfile.py) and windows (double-click the shortcut).
I don’t need to bother with the overly complicated hacking of .spec file to include data files etc.
Oh, remember to delete off the build folder after building, will save on size.
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.