Robert Colburn
Robert Colburn

Reputation: 29

ROS can't import third party libraries

I am trying to use tkinter in my ROS environment but I am having some trouble getting it set up. I added it to my packages.xml file like this

<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<depend>python-tk</depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>

but when I install the package with rosdep install [my package], the node I have import tkinter in still will not run, and instead returns ImportError: No module named tkinter. I am relatively new to ROS and have not installed third party packages before so I'm not sure if I'm missing something. Thanks in advance for any help!

Upvotes: 1

Views: 1523

Answers (1)

JWCS
JWCS

Reputation: 1201

If it's a 3rd party library/package, ros may not know how to install it. If you installed properly, rosdep should have a cache of rules to install various packages, manually created by the community. If everything is ok, when you run rosdep install my_new_pkg, it should say All required rosdeps installed successfully, or on failure report

ERROR: the following packages/stacks could not have their rosdep keys resolved to system dependencies:
my_new_pkg: Cannot locate rosdep definition for [tkinter]

This means there's no rule for how to install it, predefined. (Should it use pip/pip3? Search apt? apt install ros-version-tkinter or apt install tkinter?) This is not to say it can't be done, but it is not done without the rule being added. It will still check that it is installed, however, if you install it by another means. You can try updating your cache to the global with rosdep update, but that didn't help me for tkinter.

This is the rosdep tutorial for system deps. If you have a bunch of 3rd pary python packages, you could do the normal python env + requirements.txt file. (Biased ex, use pyenv+virtualenv + direnv to automatically call pip install on your requirements.txt) Else, you can have a hook in your CMakeLists.txt file to call pip install on your requirements.txt file before each compile, or some other means.

Edit: Remember that ROS Melodic & older use python2. In python2, according to the docs, it's import Tkinter. The lowercase import is a specification of python3.

Upvotes: 2

Related Questions