I had a similar issue when packaging up an script that used xarray
. The solution was to find out which package was importing jupyter
, and add it to the list of excluded-modules. In my case, I excluded dask
, but in your case things will be different.
I would rerun your pyinstaller command with --log-level DEBUG
in order to get some more logging information, then take a look at the log files generated in the build/ directory. If you have graphviz, or know how to work with graphs, then you can analyze the .dot file to learn about the packages that install jupyter/IPython. If you don't know how to use graphviz, no problem, just open up the html file in a browser. This file shows all of the packages imported by your script, and all of the packages that those packages import, and are imported by, etc. Beware, this is a really complex web of package A imports ... and package A is imported by ..., so don't get lost in the details.
The goal here is to find the path of imports that leads from your script to IPython/jupyter that is leading to this issue. You want to stop this path wherever seems logical for your script. In your case, many of the scipy
subpackages import matplotlib.pyplot
, which imports IPython
, which imports things which eventually import jupyter_client
. You want to sever this path from your script to jupyter/IPython as early as you can by excluding one of the packages. The package you decide to exclude will depend on your app.
The easiest way to get rid of this error would be to sever this path from your script to jupyter
by excluding matplotlib
. However, if you use matplotlib in your script to generate plots, then you can't do that. You would have to pick a package that is more downstream. Ultimately you could exclude IPython
, and that should do the trick. Take a look at the pyinstaller documentation for how to use the --exclude-module
argument:
https://pyinstaller.readthedocs.io/en/stable/usage.html#what-to-bundle-where-to-search
Or this stackoverflow question which has some more info:
How to remove/exclude modules and files from pyInstaller?
On a side note, you should start getting comfortable excluding unnecessary packages since this can drastically decrease the size of your bundled app and improve performance.