Making Use Of Py Installer. Running PyInstaller from Python rule
The syntax for the pyinstaller demand is:
Within the many easy instance, set the existing directory towards the location of one’s system myscript and execute:
PyInstaller analyzes myscript and:
- Writes myscript.spec in the exact same folder due to the fact script.
- Produces a folder build in the exact same folder because the script if it generally does not occur.
- Writes some log files and files that advance payday loans online Alaska are working the create folder.
- Produces a folder dist when you look at the exact same folder as the script if it generally does not occur.
- Writes the myscript folder that is executable the dist folder.
When you look at the dist folder you will find the bundled app you distribute to your users.
Typically you name one script from the demand line. If you identify more, each one is analyzed and included in the production. Nonetheless, the very first script called provides the title for the spec file and also for the executable folder or file. Its rule could be the very very first to perform at run-time.
For several uses you might modify the articles of myscript.spec (described under using Files that is spec). You name the spec file to PyInstaller instead of the script after you do this:
The myscript.spec file contains most of the given information supplied by the choices that have been specified when pyinstaller (or pyi-makespec) had been run with all the script file while the argument. You typically need not specify any choices whenever operating pyinstaller with the spec file. Just a few command-line choices have actually an impact when building from the spec file.
You could provide a way to the script or spec file, as an example
Reducing the CommandР’В¶
A full pyinstaller command can become very long because of its numerous options. You may run the command that is same and once again as you build your script. You can easily place the demand in a shell script or batch file, utilizing line continuations making it readable. For instance, in GNU/Linux:
Or in Windows, utilize the little-known BAT file line extension:
You may use the run function defined in PyInstaller.__main__ if you wish to run PyInstaller from Python rule, . By way of example, the code that is following
Is the same as:
Operating PyInstaller with Python optimizationsР’В¶
When utilizing this particular feature, you ought to know of the way the Python bytecode optimization system works. When-O that is using,_ is scheduled to False and assert statements are taken out of the bytecode. The flag that is-OO eliminates docstrings.
By using this function impacts not just your script that is main all modules included by PyInstaller . When your rule (or any module brought in by the script) depends on these features, your system may break or have behavior that is unexpected.
PyInstaller could be run with Python optimization flags ( -O or -OO ) by performing it as a Python module, in place of making use of the pyinstaller demand:
Or, by clearly establishing the PYTHONOPTIMIZE environment variable to a non-zero value:
Any PyInstaller can be used by you choices which can be otherwise available with all the pyinstaller demand. For instance:
Instead, you may want to utilize the way to pyinstaller:
UPX is an utility that is free for most systems. UPX compresses files that are executable libraries, making them smaller, often much smaller. UPX can be obtained for most os’s and that can compress a number that is large of file platforms. Begin to see the UPX website for packages, and also for the set of supported formats that are executable.
A compressed executable system is covered in UPX startup rule that dynamically decompresses the system as soon as the system is launched. After it’s been decompressed, the system operates ordinarily. When it comes to a PyInstaller executable that is one-file was UPX-compressed, the total execution series is:
- The compressed system begin up within the UPX decompressor code.
- The PyInstaller bootloader, which creates a temporary environment for Python after decompression, the program executes.
- The Python interpreter executes your script.
PyInstaller actively seeks UPX regarding the execution course or perhaps the course specified because of the –upx-dir option. If UPX exists, PyInstaller is applicable it to your executable that is final unless the –noupx choice was handed. UPX has been utilized with PyInstaller production frequently, frequently without any dilemmas.
Encrypting Python BytecodeР’В¶
To encrypt the Python bytecode modules stored into the bundle, pass the –key= argument that is key-string the demand line.
Because of this to the office, you’ll want to run:
The key-string is just a sequence of 16 figures which can be utilized to encrypt each file of Python byte-code prior to it being kept into the archive within the executable file.
The tinyaes are used by this feature module internally when it comes to encryption.
Determining the Extraction LocationР’В¶
In rare circumstances, when you bundle to an executable that is singlesee Bundling to 1 File and How the One-File system Functions ), you might get a handle on the positioning regarding the short-term directory at compile time. This is often done utilizing the –runtime-tmpdir option. If this choice is provided, the bootloader shall ignore any temp-folder location defined by the run-time OS. Please utilize this choice just you are doing if you know what.