ROS Kinetic创建Python3工作区出现“No module named ‘catkin_pkg‘”解决方案

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

你可能感兴趣的:(ROS学习记录,linux,python,ubuntu)