1
我目前有一些問題導入.srv文件,我定義了某處,我無法導入到我的service_def.py文件中。爲什麼這不可能?ROS導入srv消息 - 相對導入跳轉問題
我把它作爲一個rosnode的catkin_workspace我src文件看起來像這樣
.
├── CMakeLists.txt -> /opt/ros/indigo/share/catkin/cmake/toplevel.cmake
└── service
├── CMakeLists.txt
├── include
│ └── service
│ ├── __init__.py
│ ├── service_def.py
│ └── service_def.pyc
├── package.xml
├── setup.py
├── src
│ └── service_node.py
└── srv
├── get.srv
├── set.srv
└── __init__.py
service_def.py被定義爲這樣
from ..srv import *
而且我service_node.py我rosrun
進口service_def.py
import service.service_def
那麼爲什麼不能導入我的服務ce在service_def.py中的消息?
錯誤消息:
[email protected]:~/python_service/src$ rosrun service service_node.py
Traceback (most recent call last):
File "/home/k/python_service/src/service/src/service_node.py", line 5, in <module>
import service.service_def
File "/home/k/python_service/src/service/include/service/service_def.py", line 1, in <module>
from ..srv import *
ValueError: Attempted relative import beyond toplevel package
我setup.py看起來是這樣的:
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
# fetch values from package.xml
setup_args = generate_distutils_setup(
packages=['service'],
package_dir={'': 'include'},
)
setup(**setup_args)
它如何導入服務文件? –
問題在於'service_def.py'的導入。它不導入srv文件。 –
@CarltonBanks這是假設你的'setup.py'定義了服務(根據它的Traceback),而在'CMakeLists.txt'中定義了服務文件(如ROS教程中指定的那樣)。你可以看一下這個[tutorial](http://wiki.ros.org/rospy_tutorials/Tutorials/Makefile)來看看catkin使用'setup.py'的例子。 –