How to Make a Python Script Standalone Executable to Run Without Any Dependency

How can I make a Python script standalone executable to run without ANY dependency?

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 on Linux.

It is much harder to revert than common .pyo and .pyc files (and also gain in performance!).

How to make any python program run standalone

I use autopytoexe for windows applications.
It has GUI and you can save the compile settings.

https://pypi.org/project/auto-py-to-exe/

How to package Python Project into a standalone executable?

PyInstaller

PyInstaller is a program that freezes (packages) Python programs into stand-alone executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX. Its main advantages over similar tools are that PyInstaller works with Python 2.7 and 3.4—3.7, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility.

It work even if users do not have python installed.

Here an example from a github project. As you can see, you can download sources, but also a zip containing every package used to run your project. In this example, it contains many files, but you can package everything into a single .exe file.

How to use (Manual):

Install PyInstaller from PyPI:

pip install pyinstaller

Go to your program’s directory and run:

pyinstaller yourprogram.py

This will generate the bundle in a subdirectory called dist.

You can use --onefile argument in order to generate the bundle with only a single executable file.

Case specific:

You asked how to get arguments send by the user. Here is some way to do it, more or less convenient:

  • Use input(),
  • Use a config file,
  • Use default parameter.

How to run an Executable that needs packages without internet?

Since you're already using the Pyinstaller package, I'm assuming that the issue is for the packages which aren't imported in the python file as Pyinstaller automatically adds all the imported packages to the executable file. You can use the argument --hidden-import for the packages that you can't or don't want to mention in the file. For example,

pyinstaller --onefile --hidden-import libmagic app.py

See its documentation here.

How to create standalone program(on linux) from my python code?

You can try PyInstaller. It is easy to use for a simple case.

pip install pyinstaller

then for a single-file executable

pyinstaller covid_19.py --onefile

will generate the executable in the \dist directory.

PyInstaller is not cross platform, so on Windows, for example, it will create a .exe file. If you wanted an executable to work on, say, MacOS, you would need to compile on that system.

Python standalone executable

Check PyInstaller. This is an alternative to py2exe

http://www.pyinstaller.org/

pip install pyinstaller

pyinstaller yourprogram.py



Related Topics



Leave a reply



Submit