首页 > 解决方案 > 通过运行带有 -m 选项的 python,使用 bokeh image_url 绘制本地图像

问题描述

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

python -m bokeh_module.bokeh_sub_module

目录树如下所示。通过运行上述命令,无论将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)

顺便说一句,如果我pytohn bokeh_sub_module.pybokeh_module目录运行,可以找到同一目录内的 image.png 没有问题。

标签: modulewindows-10packagebokehpython-3.7

解决方案


image_url需要 URL,并且您的调用都不需要image_url使用 URL。

尝试使用绝对 URL 并file://在它们前面添加。


推荐阅读