使用散景 image_url by 运行 python 和 -m 选项绘制本地图像

Plot a local image using bokeh image_url by running python with the -m option

我必须 运行 使用顶级目录中的 -m 选项将散景脚本作为模块,因为它需要在同一目录下导入其他一些便携式模块

python -m bokeh_module.bokeh_sub_module

目录树如下所示。通过运行ning上面的命令,无论png文件放在哪里都没有显示图像,有没有办法解决这个问题?感谢您的帮助。

.
├── other_module
│   ├── __init__.py
│   └── other_sub_module.py
├── bokeh_module
│   ├── __init__.py
│   ├── image.png # not showing
│   └── bokeh_sub_module.py
└── image.png # not showing either

bokeh_sub_module.py

from other_module import other_sub_module
from bokeh.plotting import figure, show

# do something with other_sub_module
p = figure(match_aspect=True)
p.image_url( ['image.png'], 0, 0, 1, 1 ) # not showing
p.image_url( ['./bokeh_module/image.png'], 0, 0, 1, 1 ) # not showing either
show(p)

顺便说一句,如果我从bokeh_module目录下运行 python bokeh_sub_module.py,同目录下的image.png是没有问题的

image_url 需要 URL,而您对 image_url 的调用都没有使用 URL。

尽量使用绝对网址,并在其前面加上file://