Going from @Uynix, I found that I had to do a few more steps to implement the solution for my version of the problem using cx_freeze. My first solution post so let me know if more details are needed.
In summary, I had to modify the
C:\ProgramData\Anaconda3\pkgs\bokeh-0.12.9-py36_0\Lib\site-packages\bokeh\core\templates.py
The Original file (bokeh 0.12.9):
''' Provide Jinja2 templates used by Bokeh to embed Bokeh models
(e.g. plots, widgets, layouts) in various ways.
.. bokeh-jinja:: bokeh.core.templates.AUTOLOAD_JS
.. bokeh-jinja:: bokeh.core.templates.AUTOLOAD_NB_JS
.. bokeh-jinja:: bokeh.core.templates.AUTOLOAD_TAG
.. bokeh-jinja:: bokeh.core.templates.CSS_RESOURCES
.. bokeh-jinja:: bokeh.core.templates.DOC_JS
.. bokeh-jinja:: bokeh.core.templates.FILE
.. bokeh-jinja:: bokeh.core.templates.JS_RESOURCES
.. bokeh-jinja:: bokeh.core.templates.NOTEBOOK_LOAD
.. bokeh-jinja:: bokeh.core.templates.NOTEBOOK_DIV
.. bokeh-jinja:: bokeh.core.templates.PLOT_DIV
.. bokeh-jinja:: bokeh.core.templates.SCRIPT_TAG
'''
from __future__ import absolute_import
import json
from jinja2 import Environment, PackageLoader, Markup
_env = Environment(loader=PackageLoader('bokeh.core', '_templates'))
_env.filters['json'] = lambda obj: Markup(json.dumps(obj))
JS_RESOURCES = _env.get_template("js_resources.html")
CSS_RESOURCES = _env.get_template("css_resources.html")
SCRIPT_TAG = _env.get_template("script_tag.html")
PLOT_DIV = _env.get_template("plot_div.html")
DOC_JS = _env.get_template("doc_js.js")
FILE = _env.get_template("file.html")
NOTEBOOK_LOAD = _env.get_template("notebook_load.html")
NOTEBOOK_DIV = _env.get_template("notebook_div.html")
AUTOLOAD_JS = _env.get_template("autoload_js.js")
AUTOLOAD_NB_JS = _env.get_template("autoload_nb_js.js")
AUTOLOAD_TAG = _env.get_template("autoload_tag.html")
I traced the problem to the line:
JS_RESOURCES = _env.get_template("js_resources.html")
Which I discovered, somehow was not being compiled correctly by cx_freeze, throwing that same error:
File "C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\templates.py", line 27, in <module>
JS_RESOURCES = _env.get_template("js_resources.html")
File "C:\ProgramData\Anaconda3\lib\site-packages\jinja2\environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "C:\ProgramData\Anaconda3\lib\site-packages\jinja2\environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "C:\ProgramData\Anaconda3\lib\site-packages\jinja2\loaders.py", line 113, in load
source, filename, uptodate = self.get_source(environment, name)
File "C:\ProgramData\Anaconda3\lib\site-packages\jinja2\loaders.py", line 234, in get_source
if not self.provider.has_resource(p):
File "C:\ProgramData\Anaconda3\lib\site-packages\pkg_resources\__init__.py", line 1464, in has_resource
return self._has(self._fn(self.module_path, resource_name))
File "C:\ProgramData\Anaconda3\lib\site-packages\pkg_resources\__init__.py", line 1514, in _has
"Can't perform this operation for unregistered loader type"
NotImplementedError: Can't perform this operation for unregistered loader type
New templates.py file:
''' Provide Jinja2 templates used by Bokeh to embed Bokeh models
(e.g. plots, widgets, layouts) in various ways.
.. bokeh-jinja:: bokeh.core.templates.AUTOLOAD_JS
.. bokeh-jinja:: bokeh.core.templates.AUTOLOAD_NB_JS
.. bokeh-jinja:: bokeh.core.templates.AUTOLOAD_TAG
.. bokeh-jinja:: bokeh.core.templates.CSS_RESOURCES
.. bokeh-jinja:: bokeh.core.templates.DOC_JS
.. bokeh-jinja:: bokeh.core.templates.FILE
.. bokeh-jinja:: bokeh.core.templates.JS_RESOURCES
.. bokeh-jinja:: bokeh.core.templates.NOTEBOOK_LOAD
.. bokeh-jinja:: bokeh.core.templates.NOTEBOOK_DIV
.. bokeh-jinja:: bokeh.core.templates.PLOT_DIV
.. bokeh-jinja:: bokeh.core.templates.SCRIPT_TAG
'''
from __future__ import absolute_import
import json
import sys, os
import bokeh.core
# from jinja2 import Environment, PackageLoader, Markup
from jinja2 import Environment, Markup, FileSystemLoader
# add in from Uynix
def resource_path(relative_path, file_name):
""" Get absolute path to resource, works for both in IDE and for PyInstaller """
# PyInstaller creates a temp folder and stores path in sys._MEIPASS
# In IDE, the path is os.path.join(base_path, relative_path, file_name)
# Search in Dev path first, then MEIPASS
base_path = os.path.abspath(".")
dev_file_path = os.path.join(base_path, relative_path, file_name)
if os.path.exists(dev_file_path):
return dev_file_path
else:
base_path = sys._MEIPASS
file_path = os.path.join(base_path, file_name)
if not os.path.exists(file_path):
msg = "\nError finding resource in either {} or {}".format(dev_file_path, file_path)
print(msg)
return None
return file_path
""" my new code here
"""
_env = Environment(loader=FileSystemLoader(os.path.dirname(bokeh.core.__file__) +'\\_templates'))
""" end of my new code
"""
_env.filters['json'] = lambda obj: Markup(json.dumps(obj))
# this is where the errors start to happen! need to replace get_template!
JS_RESOURCES = _env.get_template("js_resources.html")
CSS_RESOURCES = _env.get_template("css_resources.html")
SCRIPT_TAG = _env.get_template("script_tag.html")
PLOT_DIV = _env.get_template("plot_div.html")
DOC_JS = _env.get_template("doc_js.js")
FILE = _env.get_template("file.html")
NOTEBOOK_LOAD = _env.get_template("notebook_load.html")
NOTEBOOK_DIV = _env.get_template("notebook_div.html")
AUTOLOAD_JS = _env.get_template("autoload_js.js")
AUTOLOAD_NB_JS = _env.get_template("autoload_nb_js.js")
AUTOLOAD_TAG = _env.get_template("autoload_tag.html")
Then ran cx_freeze etc again, and this time bokeh now works!