Skip to content Skip to sidebar Skip to footer

Can't Perform This Operation For Unregistered Loader Type

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 a

Solution 1:

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 importEnvironment, PackageLoader, Markup

to the following:

import json
import sys, os
import bokeh.corefrom jinja2 importEnvironment, 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.

Solution 2:

Bokeh relies heavily on Jinja2 for its operation. There appears to be a problem between Jinja and Pyinstaller:

https://github.com/pyinstaller/pyinstaller/issues/1898

So this may simply not be possible unless these downstream issues have been resolved.

Post a Comment for "Can't Perform This Operation For Unregistered Loader Type"