The information above covers most normal uses of PyInstaller . However, the variations of Python and third-party libraries are endless and unpredictable. It may happen that when you attempt to bundle your app either PyInstaller itself, or your bundled app, terminates with a Python traceback. Then please consider the following actions in sequence, before asking for technical help.
The PyInstaller FAQ page has work-arounds for some common problems. Code examples for some advanced uses and some common problems are available on our PyInstaller Recipes page. Some of the recipes there include:
and others. Many of these Recipes were contributed by users. Please feel free to contribute more recipes!
step runs, it produces error and warning messages.
These display after the command line if the
option allows it.
Analysis also puts messages in a warnings file
Analysis creates a message when it detects an import
and the module it names cannot be found.
A message may also be produced when a class or function is declared in
a package (an
module), and the import specifies
. In this case, the analysis can’t tell if name is supposed to
refer to a submodule or package.
The “module not found” messages are not classed as errors because typically there are many of them. For example, many standard modules conditionally import modules for different platforms that may or may not be present.
All “module not found” messages are written to the
They are not displayed to standard output because there are many of them.
Examine the warning file; often there will be dozens of modules not found,
but their absence has no effect.
When you run the bundled app and it terminates with an ImportError, that is the time to examine the warning file. Then see Helping PyInstaller Find Modules below for how to proceed.
On each run
writes a cross-referencing file about dependencies
into the build folder:
directory is an HTML file that lists the full
contents of the import graph, showing which modules are imported
by which ones.
You can open it in any web browser.
Find a module name, then keep clicking the “imported by” links
until you find the top-level import that causes that module to be included.
If you specify
additionally generates a
input file representing the
The file is
You can process it with any
a graphical display of the import dependencies.
These files are very large because even the simplest “hello world” Python program ends up including a large number of standard modules. For this reason the graph file is not very useful in this release.
PyInstaller sometimes terminates by raising a Python exception. In most cases the reason is clear from the exception message, for example “Your system is not supported”, or “Pyinstaller requires at least Python 2.7”. Others clearly indicate a bug that should be reported.
One of these errors can be puzzling, however:
needs to bundle the Python library, which is the
main part of the Python interpreter, linked as a dynamic load library.
The name and location of this file varies depending on the platform in use.
Some Python installations do not include a dynamic Python library
by default (a static-linked one may be present but cannot be used).
You may need to install a development package of some kind.
Or, the library may exist but is not in a folder where
The places where
looks for the python library are
different in different operating systems, but
are checked in most systems.
If you cannot put the python library there,
try setting the correct path in the environment variable
in GNU/Linux or
in OS X.
option (and its
) provides a
signficiant amount of diagnostic information.
This can be useful during development of a complex package,
or when your app doesn’t seem to be starting,
or just to learn how the runtime works.
Normally the debug progress messages go to standard output.
option is used when bundling a Windows app,
they are sent to any attached debugger. If you are not using a debugger
(or don’t have one), the
the free (beer) tool can be used to
display such messages. It has to be started before running the bundled
Mac OS app they are not displayed.
Consider bundling without
for your production version.
Debugging messages require system calls and have an impact on performance.
You can build the app with the
Getting Debug Messages
which will pass the
(verbose imports) flag
to the embedded Python interpreter.
This can be extremely useful.
It can be informative even with apps that are apparently working,
to make sure that they are getting all imports from the bundle,
and not leaking out to the local installed Python.
Python verbose and warning messages always go to standard output
and are not visible when the
option is used.
Remember to not use this for your production version.
If you are using the
your bundled application ay fail to start with an error message like
In this case, you will want to get more verbose output to find out
what is going on.
--windowedoption. Then you can run the resulting executable from the command line, i.e.:
--windowedoption. Anyway, if a your GUI application fails, you can run your application on the command line, i.e.
This should give you the relevant error that is preventing your application from initializing, and you can then move on to other debugging steps.
If you use the –onefile and it fails to run you program with error like:
./hello: error while loading shared libraries: libz.so.1: failed to map segment from shared object: Operation not permitted
This can be caused by wrong permissions for the /tmp directory
(e.g. the filesystem is mounted with
A simple way to solve this issue is to set,
in the environment variable TMPDIR,
a path to a directory in a filesystem mounted without
If Analysis recognizes that a module is needed, but cannot find that module,
it is often because the script is manipulating
The easiest thing to do in this case is to use the
to list all the other places that the script might be searching for imports:
pyi-makespec --paths=/path/to/thisdir \ --paths=/path/to/otherdir myscript.py
These paths will be noted in the spec file.
They will be added to the current
Python allows a script to extend the search path used for imports
of an imported module has only one entry,
the directory in which the
is free to extend its
to include other directories.
For example, the
module actually resolves to
This is because
of an imported module
is not actually executed during analysis,
changes it makes to
are not seen by
We fix the problem with the same hook mechanism we use for hidden imports,
with some additional logic; see
理解 PyInstaller 挂钩
Note that manipulations of
hooked in this way apply only
to the Analysis.
At runtime all imports are intercepted and satisfied from within the
is resolved the same
knows nothing of
Once in a while, that’s not enough.
More bizarre situations can be accomodated with runtime hooks. These are small scripts that manipulate the environment before your main script runs, effectively providing additional top-level code to your script.
There are two ways of providing runtime hooks.
You can name them with the option
Second, some runtime hooks are provided.
At the end of an analysis,
the names in the module list produced by the Analysis phase are looked up in
This text file is the string representation of a
Python dictionary. The key is the module name, and the value is a list
of hook-script pathnames.
If there is a match, those scripts are included in the bundled app
and will be called before your main script starts.
Hooks you name with the option are executed
in the order given, and before any installed runtime hooks.
If you specify
then the execution order at runtime will be:
Hooks called in this way, while they need to be careful of what they import,
are free to do almost anything.
One reason to write a run-time hook is to
override some functions or variables from some modules.
A good example of this is the Django runtime
Django imports some modules dynamically and it is looking
files are not available in the one-file bundle.
We need to override the function
in a way that will just return a list of values.
The runtime hook does this as follows:
import django.core.management def _find_commands(_): return """cleanup shell runfcgi runserver""".split() django.core.management.find_commands = _find_commands
If you have some reason to think you have found a bug in PyInstaller you can try downloading the latest development version. This version might have fixes or features that are not yet at PyPI . You can download the latest stable version and the latest development version from the PyInstaller Downloads page.
You can also install the latest version of PyInstaller directly using pip :
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip