Why can't I import a Python dependency even if it is declared as a runtime dependency in package.xml?
I have the following dependencies in my package.xml
<buildtool_depend>catkin</buildtool_depend>
<build_depend>message_filters</build_depend>
<build_depend>rosbag</build_depend>
<build_depend>rospy</build_depend>
<build_depend>tf</build_depend>
<build_export_depend>message_filters</build_export_depend>
<build_export_depend>rosbag</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>tf</build_export_depend>
<exec_depend>message_filters</exec_depend>
<exec_depend>rosbag</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>tf</exec_depend>
<exec_depend>python-h5py</exec_depend>
<exec_depend>python-opencv</exec_depend>
<exec_depend>python-pandas</exec_depend>
<exec_depend>python-tqdm</exec_depend>
I have done rosdep install my_package
and catkin build
inside my workspace (and I got no error). However, whenever I try to do pip list
or to import any of the Python dependencies I specified above, such as Pandas or OpenCV, I get an ImportError
or I don't see them in the list. I want to use those Python dependencies in my scripts or source files inside my_package
.
If the correct way of specifying Python dependencies is by specifying them in <exec_depend>
(see e.g. http://docs.ros.org/lunar/api/catkin/html/howto/format2/python_module_dependencies.html)), then why can't I see pandas
when doing pip list
?
What is the output of
which python
andpython --version
?Edit: I doubt
<build_export_depend>rospy</build_export_depend>
is needed:rospy
is a pure Python package. It cannot be abuild_export_depend
as there are no headers for other (C++) packages to depend on/include.In general: I would guess 99% of Python dependencies would be only
exec_depend
s.The output of the first command is
/home/me/catkin_ws/src/my_package/venv/bin/python
and of the second isPython 2.7.15+
. I am inside a virtual environment, as you can see.Regarding the
<build_export_depend>rospy</build_export_depend>
, it was added automatically when I usedcatkin create pkg --catkin-deps rospy rosbag tf message_filters -- my_package
.Yes, it does that. But that is just because there is no support for Python packages specifically. You can remove all dependencies other than
exec_depend
s from your manifest. Unless you have a mixed C++/Python package, that is.@gvdhoorn How do I know which packages contain only Python code? Now, you told me that
rospy
only needs to be specified as aexec_depend
, because it only contains Python code. In general, though, is there a way of knowing whether a dependency only contains Python code, without having to look at the source code?"only contain Python code" is just a shortcut.
build_export_depend
is only used for telling packages that depend on you that they also (transitively) depend on your exported dependencies.So if you have a header (C++) that includes
a.hpp
, which comes from packagepkg_a
, then in order for dependants of your package to be able to include your headers, they must also havepkg_a
, or your headers will fail compilation with acannot find 'pkg_a/a.hpp'
.Python is not a compiled language, so this cannot happen. Ergo: no
build_export_depend
s.Unless you have a mixed C++/Python package, have C++/C bindings or are doing other more complex things.
@gvdhoorn However, you did not answer my specific question above about "how do I determine whether a package only needs to be specified as
exec_depend
, only contains Python code, or is or not required at build time. Maybe I will ask another question on the website.You really need me to explain you how to determine that a package "only contains Python code"?
There is no single command or fool proof way to see that from anything other than by looking at all the sources that make up the package.
Also: you add
build_export_depend
s to your package. As you are -- presumably -- the author of your own source code, you should know whether you are#include
-ing anything from your dependencies in your own headers. You should also know whether you are creating a Python-only package.build_export_depend
s communicate to your users which packages your package is using. Not the other way around.