module - 通过运行带有 -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.py
从bokeh_module
目录运行,可以找到同一目录内的 image.png 没有问题。
解决方案
image_url
需要 URL,并且您的调用都不需要image_url
使用 URL。
尝试使用绝对 URL 并file://
在它们前面添加。
推荐阅读
- python - 有没有办法将列表中的值作为熊猫中的列?我不想重命名列,而是将列表值添加为列
- python - 变量未按预期更新
- swift - 从 Firebase 高效地获取多个图像
- clang - C++ 项目在 clang 切换后从终端编译,但不是从 CLion
- javascript - 如何制作像“Discord”这样的测试语音条?
- sql - SQL hierarchyid 类型问题
- java - 无法使用单个消息转换创建 Kafka Redis Sink
- r - R - 如何使用来自两个数据帧的数据来计算 R 中的新变量?
- excel - VBA 程序可以看到(并关闭?)它没有创建的打开的数据库连接吗?
- powershell - 如何防止powershell脚本中的Set-Location改变调用shell的路径