ROS Kinetic建立Python3工作區出現「No module named ‘catkin_pkg‘」解決方案

2020-09-28 10:01:03

ROS Kinetic建立Python3工作區出現如下問題解決方案

ImportError: 「from catkin_pkg.package import parse_package」 failed: No module named ‘catkin_pkg’
Make sure that you have installed 「catkin_pkg」, it is up to date and on the PYTHONPATH.

官方教學中提供了ROS Kinetic支援Python3的方法,原文如下

Python 3 users in ROS Melodic and earlier: note, if you are building ROS from source to achieve Python 3 compatibility, and have setup your system appropriately (ie: have the Python 3 versions of all the required ROS Python packages installed, such as catkin) the first catkin_make command in a clean catkin workspace must be:

$ catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

This will configure catkin_make with Python 3. You may then proceed to use just catkin_make for subsequent builds.

你需要安裝所有ROS Python包的Python3版本,比如catkin,並且在一個乾淨的工作區的 第一條命令 必須是

catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

我在執行完這一步後報了這樣的錯

ImportError: 「from catkin_pkg.package import parse_package」 failed: No module named ‘catkin_pkg’
Make sure that you have installed 「catkin_pkg」, it is up to date and on the PYTHONPATH.

查詢此檔案,發現該檔案在/usr/lib/python2.7/dist-packages/catkin_pkg,應該就是上邊提到的沒有安裝ROS Python包的Python3版本所導致的。於是安裝Python3版本的catkin_pkg

sudo apt install python3-pip
pip3 install catkin_pkg

安裝完成後再執行

catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

執行成功,沒有報錯,工作區成功建立。
在系統下查詢catkin_pkg檔案,路徑為

/usr/lib/python2.7/dist-packages/catkin_pkg
/home/free/.local/lib/python3.5/site-packages/catkin_pkg

當然,現在只是建立成功了Python3工作區,至於能不能用,還有沒有其它問題,那我就不知道了,因為我也沒有在ROS下寫過Python