Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comprehensive tutorial on Pyinstaller? [closed]

People also ask

Why is my PyInstaller not working?

The most common reason a PyInstaller package fails is that PyInstaller failed to bundle a required file. Such missing files fall into a few categories: Hidden or missing imports: Sometimes PyInstaller can't detect the import of a package or library, typically because it is imported dynamically.

Which is better py2exe or PyInstaller?

In PyInstaller it is easy to create one exe, By default both create a bunch of exes & dlls. In py2exe its easier to embed manifest file in exe, useful for run as administrator mode in windows vista and beyond. Pyinstaller is modular and has a feature of hooks to include files in the build that you like.


Both guides in the accepted answer seem outdated. PyInstaller now provides an executable script that allows you to do

pyinstaller your_script.py

wherever your_script.py is located - instead of the old mode of copying your your_script.py to wherever you copied the source code of PyInstaller.

Here's a brief, more recent guide that walks you through a simple Hello World example:

http://www.pythoncentral.io/pyinstaller-package-python-applications-windows-mac-linux/


Have you looked here: simplified tutorial

Or here: a bit longer tutorial

EDIT: Adding data files is implied in the second tutorial. If you use the second example just before the "Wrapping Up" section, along with the official documentation: Analysis, it looks like you'd specify your data-file dependencies as part of the "datas" subobject when calling the Analysis() function.

EDIT2: From official documentation: "Generally, you will not need to create your own PKGs, as the EXE will do it for you. This is one way to include read-only data in a single-file deployment, however. A single-file deployment including TK support will use this technique."

Example (should be roughly like this):

a = Analysis(...)
pyz = PYZ(a.pure)
pkg = PKG(a.pure, name="PackageName")
exe = EXE(pyz, pkg,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          ...)

To Create one executable of your python script or project
create your script or project. To install pyinstaller on Windows type

pip install pyinstaller
Now open command prompt and type the command
pyinstaller --onefile myscripy.py
You will find a dist folder created. Browse dist folder and you will get .exe file of python script.