Choregraphe行为块代码导入本地Pillow/Numpy库报错求助
解决Choregraphe中Pillow导入错误:ImportError: cannot import name _imaging
这个ImportError: cannot import name _imaging问题我之前帮不少开发者解决过,本质是Pillow的二进制依赖没有和Choregraphe自带的Python环境匹配——毕竟Choregraphe通常会自带独立的Python解释器,和你系统里的Python不是一回事。下面给你几个针对性的解决步骤:
1. 确认Choregraphe的Python版本
首先得搞清楚Choregraphe用的是哪个版本的Python,不然装错Pillow版本肯定出问题:
- 打开Choregraphe,点击顶部菜单栏的
Tools > Python Console - 在控制台里输入以下代码并执行:
记下输出的版本号(比如import sys print(sys.version)3.7.9),后面安装Pillow要对应这个版本。
2. 用Choregraphe自带的Pip重新安装Pillow
不要用系统的pip安装,一定要用Choregraphe自带的pip工具,这样才能保证Pillow和Choregraphe的Python环境兼容:
- 找到Choregraphe安装目录下的pip路径:
- Windows系统:一般是
C:\Program Files\Softbank Robotics\Choregraphe Suite X.X\python\Scripts\pip.exe - Linux系统:通常是
/opt/softbank Robotics/Choregraphe Suite X.X/python/bin/pip
- Windows系统:一般是
- 打开终端/命令行,运行以下命令(替换成你的实际路径):
这个命令会把对应版本的Pillow直接安装到你的行为文件夹里。# Windows示例 "C:\Program Files\Softbank Robotics\Choregraphe Suite 2.5\python\Scripts\pip.exe" install pillow --target="C:\path\to\your\behavior\folder" # Linux示例 /opt/softbank Robotics/Choregraphe Suite 2.5/python/bin/pip install pillow --target=/path/to/your/behavior/folder
3. 调整导入路径的优先级
有时候系统的Python路径会优先于你添加的行为文件夹路径,导致导入了系统里不兼容的Pillow版本。修改你的代码,把路径插入到最前面:
from sys import path # 用insert(0, ...)代替append,让行为文件夹的路径优先加载 path.insert(0, ALFrameManager.getBehaviorPath(self.behaviorId)) from PIL import Image import numpy as np # 建议用numpy的array替代scipy的,更规范且减少冲突 from scipy import inf from scipy.sparse.csgraph import shortest_path, csgraph_from_dense
4. 检查Pillow安装完整性
安装完成后,去你的行为文件夹里找到PIL文件夹,检查是否存在_imaging.cpXX-win_amd64.pyd(Windows)或_imaging.cpython-XXm-x86_64-linux-gnu.so(Linux)这类文件:
- 如果缺失,说明安装过程中二进制编译失败了,建议删除
PIL文件夹和Pillow-*.dist-info文件夹,重新用上面的命令安装。
内容的提问来源于stack exchange,提问作者Cato
相关产品推荐
相关产品推荐

