I'm using bokeh for data visualization, and trying to make an executable but it shows an error message of "can't perform this operation for unregistered loader type"
I have tried as a solution of init.py to the directory (+subdir) of my script.py, but it's not work.
PS. Win10, Python 3.6.3, pyinstaller 3.4, bokeh 0.12.13
from bokeh.plotting import figure, show p = figure(width=800, height=400, title="Money") p.title.text_color = "green" p.title.text_font_size = "18pt" p.xaxis.axis_label = "Time" p.xaxis.axis_label_text_color = "violet" p.yaxis.axis_label = "Money" p.yaxis.axis_label_text_color = "violet" dashs = [12, 4] listx1 = [1,5,7,9,13,16] listy1 = [15,50,80,40,70,50] p.line(listx1, listy1, line_width=4, line_color="red", line_alpha=0.3, line_dash=dashs, legend="Idle") show(p)
Error message: enter image description here
Thx in advance for your help
Ran into the same error using pyinstaller.
This should solve your problem and the problem of not finding jinja2 that will follow:
edit the file: your-python-env\Lib\site-packages\bokeh\core\templates.py
(nb: change your-python-env to wherever you've installed python)
and change the import statements from:
import json from jinja2 import Environment, PackageLoader, Markup
to the following:
import json import sys, os import bokeh.core from jinja2 import Environment, FileSystemLoader, Markup
Next, find the line where it says:
_env = Environment(loader=PackageLoader('bokeh.core', '_templates'))
comment this out and replace it with this code:
# _env = Environment(loader=PackageLoader('bokeh.core', '_templates')) if getattr(sys, 'frozen', False): # we are running in a bundle templatedir = sys._MEIPASS else: # we are running in a normal Python environment templatedir = os.path.dirname(bokeh.core.__file__) _env = Environment(loader=FileSystemLoader(templatedir + '\\_templates'))
(adapted from: https://pythonhosted.org/PyInstaller/runtime-information.html)
What this does is that when the code is frozen, it redirects the jinja2 looking to sys._MEIPASS (which is the folder where your distribution is). Specifically it looks for the jinja2 templates at sys._MEIPASS_templates. When frozen, the file points to the wrong location, hence the original problem.
So now, we have to make sure the jinja2 files end up at the _templates folder. To do this we edit the pyinstaller .spec. This works for compiling to one directory or one file. Edit the datas in your .spec file to:
a = Analysis(['graphms-gui.py'], pathex=['C:\\Users\\choom.000\\Documents\\forcompile270218'], binaries=, datas=[(r'your-python-env\Lib\site-packages\bokeh\core\_templates','_templates'), ], hiddenimports=, hookspath=, runtime_hooks=, excludes=, win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher)
What this does is it gets the contents of the core_template folder and copies it to dist_templates. Which is exactly where we've pointed the templates.py to look for the jinja2 files.
This resolved the problem for me with pyinstaller==3.3.1, bokeh==0.12.9 and jinja2==2.10.
Bokeh relies heavily on Jinja2 for its operation. There appears to be a problem between Jinja and Pyinstaller:
So this may simply not be possible unless these downstream issues have been resolved.