2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ROS Python - 自作サービスのインポートエラー

Last updated at Posted at 2021-01-05

エラー

Pythonノードで自作Serviceのライブラリが読み込めないエラーが発生しました

my_server.py
...

from my_servs.srv import *

...
error
Traceback (most recent call last):
  File "/home/hoshina/catkin_ws/src/pca_server/scripts/pca_server.py", line 3, in <module>
    from pca_server_srvs.srv import *
ModuleNotFoundError: No module named 'pca_server_srvs'

serviceのpythonライブラリが生成されているか確認

ls ~/catkin_ws/devel/lib/python3/dist-packages 

>> my_srvs 
生成されていればオッケー

>> 
何も出なければだめ

次のサンプルをビルドしてserviceのライブラリが生成されるか確認
https://github.com/fairlight1337/ros_service_examples

git clone https://github.com/fairlight1337/ros_service_examples.git

catkin build

ls ~/catkin_ws/devel/lib/python3/dist-packages 

>> ros_service_examples
オッケー,このリポジトリのCMakeLists.txtとpackage.xmlを参考にして、自分のものを修正する

エラーが治らない場合

pythonに以下を追加してライブラリのパスが通っているか確認

import sys
print(sys.path)

パスが通っていない場合は

source ~/catkin_ws/devel/setup.bash

をしたり、ターミナルを再立ち上げしたりする

C++でincludeできない場合

catkin_ws/devel/include/ 内にヘッダーファイルが生成されているか確認

ない場合

serviceパッケージのCMakeLists.txt内に

generate_messages()

を入れ忘れている可能性大

環境

  • ubuntu 20.04
  • ros noetic
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?