无法针对未注册的加载器类型执行此操作 [英] can't perform this operation for unregistered loader type
问题描述
我正在使用bokeh进行数据可视化,并尝试制作可执行文件,但显示错误消息无法对未注册的加载器类型执行此操作"
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"
我已尝试将 init .py解析为script.py的目录(+ subdir),但这是行不通的.
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
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)
错误消息: 在此处输入图片描述
提前致谢
推荐答案
使用pyinstaller遇到相同的错误.
Ran into the same error using pyinstaller.
这应该可以解决您的问题以及找不到随后出现的jinja2的问题:
This should solve your problem and the problem of not finding jinja2 that will follow:
编辑文件:your-python-env \ Lib \ site-packages \ bokeh \ core \ templates.py
edit the file: your-python-env\Lib\site-packages\bokeh\core\templates.py
(nb:将您的python-env更改为您安装python的位置)
(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
到以下:
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'))
(改编自: https://pythonhosted.org/PyInstaller/runtime-information.html )
这是因为冻结代码后,它将jinja2重定向到sys._MEIPASS(这是您的发行版所在的文件夹).具体来说,它将在sys._MEIPASS_templates查找jinja2模板.冻结后,文件指向错误的位置,因此是原始问题.
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.
所以现在,我们必须确保jinja2文件最终位于_templates文件夹中.为此,我们编辑pyinstaller .spec.这适用于编译到一个目录或一个文件.将.spec文件中的数据编辑为:
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)
它的作用是获取core_template文件夹的内容并将其复制到dist_templates.这正是我们指向templates.py查找jinja2文件的地方.
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.
这对我来说解决了pyinstaller == 3.3.1,bokeh == 0.12.9和jinja2 == 2.10的问题.
This resolved the problem for me with pyinstaller==3.3.1, bokeh==0.12.9 and jinja2==2.10.
这篇关于无法针对未注册的加载器类型执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!