![]() ![]() ![]() Let’s start with an extremely simple use case: a single Python file called hello.py with the following contents: print("Hello world") This is an advanced topic, and if you need to do this, I suggest you read the manual page on spec files. ![]() This spec file tells PyInstaller exactly how to process your script. This is done by modifying the so-called spec file PyInstaller creates on the first run. If your software requires data files, you’ll need to tell PyInstaller explicitly. PyInstaller includes ‘hooks’ for well-known packages that do these things, so chances are you won’t ever need to do this! Specifying data files In these cases, you can manually supply pyinstaller the extra modules to include. Some modules do more peculiar things, like using importlib to import other modules. This process repeats until it has all the required files to include. For example, if you import a package like the built-in JSON library, it will load the JSON module’s code and analyze any imports found in there. PyInstaller analyses your code and finds all the import statements. E.g., most software will have at least a couple of import statements, importing either built-in Python modules or externally downloaded modules. When packaging your Python project, PyInstaller must determine which modules to include. The installation will only succeed if the bootloader got built. When you pip install PyInstaller, this bootloader is created once. Hence you can expect to see two processes being launched: first the bootloader and then your own Python code. This process is separated from your actual Python program. PyInstaller creates a so-called bootloader, which bootstraps your Python program. Let’s dive deeper and see how PyInstaller does its magic. It contains all the required files in a single, flat directory. The other mode (single directory) is a directory you can share with someone. This single file extracts itself into a temporary directory and runs the extracted code. exe on Windows, that you can share with someone. The most elegant (in terms of distributing your program) is the one-file mode. PyInstaller officially supports Windows 8 and up, macOS, and Linux, with some limitations you’ll learn about further on. If you use Poetry or Pipenv, add it as a developer dependency. If you don’t know these tools, please follow the links and read up about them. The package name you need is pyinstaller, so for a regular pip install, that would be: Use pip install, Poetry, or Pipenv to install the package. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |