【问题标题】:Plot a local image using bokeh image_url by running python with the -m option通过运行带有 -m 选项的 python,使用 bokeh image_url 绘制本地图像
【发布时间】:2022-05-09 06:33:03
【问题描述】:

我必须使用顶层目录中的 -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)

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

【问题讨论】:

    标签: module windows-10 package bokeh python-3.7


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      • 2022-01-08
      相关资源
      最近更新 更多