ros中报错AttributeError: module 'xxx' has no attribute 'xxx'

问题:ros中,导入自定义的模块时,报错AttributeError: module 'xxx' has no attribute 'xxx',直接运。py脚本正常

原因:ros默认先搜索根目录下的文件

解决方案:在导入自定义的模块前,先设置搜索路径

path = os.path.abspath(".")
sys.path.insert(0, path+'/src/xxx/scripts')
 
如果要用launch文件,
path = os.path.abspath("工作空间目录")
因为launch文件默认工作目录在 /home/pi/.ros
posted @ 2023-05-03 10:21  linjun123  阅读(961)  评论(0)    收藏  举报