Reducing bokeh footprint in venv (for Pyinstaller)

I’ve created an app with wxPython, using Bokeh generated html files for all plots (not a Bokeh server). I wonder if anyone has any tips about how to reduce the footprint of my PyInstaller executable?

That is, are there any folders in my site-packages (for Bokeh) that are safe to delete, knowing I’m not using bokeh serve? Or perhaps alternate ways to install into my venv with fewer features?

For that matter, are there any python libraries bokeh requires but only are used when using bokeh serve (e.g., maybe Tornado)?

Tornado is probably the only dependency you can safely leave out. There was a time in the first few years where we worked to make NumPy optional but that’s no longer the case. There is about ~1MB in the sampledata directory you could delete, assuming you are not using it. If you are using CDN resources, you can delete everything under server/static. If you are using inline resources, I believe you can delete everything except the .min.js files at the top level of server/static (test it out).

cc @mateusz

Thanks Bryan! I was successful with removing tornado and the sampledata directory contents (directory still needed to exist). It looks like PyInstaller already ignores the sampledata directory contents though?

Removing server/static contents was substantial, but I’m not familiar with CDN or inline. I looked here, and I think using CDN means my users would need internet access? Given the app is used primarily in patient/medical environments, I don’t want to make that requirement for my app.

Is the correct way to specify inline resources?
html_str = get_layout_html(bokeh_layout, resources=Resources(mode='inline'))

Interestingly, removing everything except *.min.js in server/static worked just fine without specifying resources as above. I did, however, need to clear out my .pyc files after deleting everything but *.min.js files to get the Pyinstaller executable to work properly.

For what it’s worth:
Bokeh 1.4.0
Python 3.6
macOS 10.14.6
PyInstaller 3.6

server/static after deleting *.pyc

CDN resources (which are the default for most things) load the BokehJS scripts over the internet from Inline resources mean the BokehJS scripts that ship with the Python package are injected directly in the output, so that there is no need to load from CDN. However, unlike most other things, the default resource type for get_layout_html is actually inline resources, so if that’s all you are using then you don’t need to do anything at all.

Did you remove the lib directory under bokeh/static as well? When I said everything except *.min.js that includes those entire subdirectories.

I had not been removing the contents of those directories. After removing the compiler, lib, and types directories, my PyInstaller executable file size dropped from 78.5MB to 77.9MB.

Thanks again Bryan. This saved me 21.3MB.