importerror catkin_pkg
Problem
I reinstalled ROS1 Kinetic on Ubuntu 16.04 since I realized I had been using pip, apt, and virtualenvs in the wrong way.
In my system environment, I installed ROS Kinetic following the guidelines which worked fine. However when I run
sudo rosdep init
I get:
Traceback (most recent call last):
File "/usr/bin/rosdep", line 3, in <module>
from rosdep2.main import rosdep_main
File "/usr/lib/python2.7/dist-packages/rosdep2/__init__.py", line 45, in <module>
from .lookup import RosdepDefinition, RosdepView, RosdepLookup, \
File "/usr/lib/python2.7/dist-packages/rosdep2/lookup.py", line 41, in <module>
from .rospkg_loader import RosPkgLoader
File "/usr/lib/python2.7/dist-packages/rosdep2/rospkg_loader.py", line 37, in <module>
import catkin_pkg.package
ImportError: No module named catkin_pkg.package
I had solved this before by installing it with pip instead of with apt but this apparently isn't the recommended method. I've also encountered other similar import errors before where python doesn't recognize packages installed with apt.
Details
dpkg -L python-catkin-pkg
yields:
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/python-catkin-pkg
/usr/share/doc/python-catkin-pkg/copyright
/usr/share/doc/python-catkin-pkg/changelog.Debian.gz
/usr/lib
/usr/lib/python2.7
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/catkin_pkg-0.4.6.egg-info
/usr/lib/python2.7/dist-packages/catkin_pkg-0.4.6.egg-info/top_level.txt
/usr/lib/python2.7/dist-packages/catkin_pkg-0.4.6.egg-info/dependency_links.txt
/usr/lib/python2.7/dist-packages/catkin_pkg-0.4.6.egg-info/entry_points.txt
/usr/lib/python2.7/dist-packages/catkin_pkg-0.4.6.egg-info/PKG-INFO
/usr/lib/python2.7/dist-packages/catkin_pkg-0.4.6.egg-info/requires.txt
/usr/bin
/usr/bin/catkin_find_pkg
/usr/bin/catkin_create_pkg
/usr/bin/catkin_test_changelog
/usr/bin/catkin_prepare_release
/usr/bin/catkin_package_version
/usr/bin/catkin_tag_changelog
/usr/bin/catkin_generate_changelog
dpkg -L ros-kinetic-catkin
yields:
/.
/opt
/opt/ros
/opt/ros/kinetic
/opt/ros/kinetic/setup.bash
/opt/ros/kinetic/lib
/opt/ros/kinetic/lib/python2.7
/opt/ros/kinetic/lib/python2.7/dist-packages
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin-0.7.11.egg-info
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/workspace_vcs.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/package_version.pyc
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/tidy_xml.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/cmake.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/tidy_xml.pyc
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/init_workspace.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/terminal_color.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/test_results.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/environment_cache.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/workspace.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/find_in_workspaces.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/find_in_workspaces.pyc
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/package_version.py
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/builder.pyc
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/init_workspace.pyc
/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/__init__.py
/opt/ros ...
What version of the modules do you have installed?
dpkg -L python-catkin-pkg-modules
Updated the question with that output:
0.4.6
And where is the
catkin_pkg
module being found?python -c "import catkin_pkg; print(catkin_pkg.__file__)"
That command is the one that's not working:
ImportError: No module named catkin_pkg
. I tried all instructions in related questions.Can you share the search path:
python -c "import sys; print(sys.path)"
updated the question
Please try to unset the
PYTHONPATH
by invokingunset PYTHONPATH
. Then trypython -c "import catkin_pkg; print(catkin_pkg.__file__)"
andpython -c "import sys; print(sys.path)"
again.The import still fails, even after restarting the terminal.
sys.path
does contain/usr/lib/python2.7/dist-packages
now though.sys.path
already contained/usr/lib/python2.7/dist-packages
before. Are there any other paths before that one now? If yes, please check there content since they might interfere with the lookup.You're right, missed that in the diff. Now most packages come before that one in the list. What should I be checking for? Can or should I reset this list? Should I explicitly add this line to the beginning of
PYTHONPATH
?I added it to the front of the list through
PYTHONPATH
so that it's first (after''
) in the list. The import still errors.What's the output of
import catkin_pkg
, and if that works, what's the output ofimport inspect; inspect.getsourcefile(catkin_pkg)
?Also, what's the output of
import imp; imp.find_module('catkin_pkg')
?As I mentioned above,
import catkin_pkg
only works when I dopip install catkin_pkg
. When I do that, I get `/home/achille/.local/lib/python2.7/site-packages/catkin_pkg
for bothimp
andinspect
. Without the pip install, obviously neither works.Any change in behavior after reinstalling python-catkin-pkg-modules?
sudo apt install --reinstall python-catkin-pkg-modules
Not sure why or how but that did it! Please do add it as the answer to this question.