本文介绍了通过使用-m选项运行python,使用bokeh image_url绘制本地图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to run a bokeh script as a module using the -m option from the top directory, because it needs to import some other portable module under the same directory

python -m bokeh_module.bokeh_sub_module

目录树如下所示.通过运行以上命令,无论将png文件放在何处都不会显示图像,有没有办法解决此问题?谢谢您的帮助.

The directory tree is shown below. By running the above command, it doesn't show the image no matter where the png file is placed, is there a way to resolved the issue? Thank you for any help.

.
├── 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

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 目录运行 pytohn bokeh_sub_module.py ,则可以毫无问题地找到同一目录下的image.png.

By the way, if I run pytohn bokeh_sub_module.py from the bokeh_module directory, the image.png inside the same directory can be found with no problems.

推荐答案

image_url 需要URL,而您对 image_url 的调用均未使用URL.

image_url requires URLs, and neither of your calls to image_url use URLs.

尝试使用绝对URL,并在其前面添加 file://.

Try to use absolute URLs and add file:// in front of them.

这篇关于通过使用-m选项运行python,使用bokeh image_url绘制本地图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:49