系统: ubtuntu 16.04
ros版本: kinetic
输入命令
catkin_create_pkg test01 roscpp tf snesor_msgs
返回的结果:
Traceback (most recent call last):
File "/usr/local/bin/catkin_create_pkg", line 7, in
from catkin_pkg.cli.create_pkg import main
File "/usr/local/lib/python3.5/dist-packages/catkin_pkg/cli/create_pkg.py", line 9, in
from catkin_pkg.package_templates import create_package_files, PackageTemplate
File "/usr/local/lib/python3.5/dist-packages/catkin_pkg/package_templates.py", line 42, in
from catkin_pkg.package import Dependency
File "/usr/local/lib/python3.5/dist-packages/catkin_pkg/package.py", line 44, in
from catkin_pkg.condition import evaluate_condition
File "/usr/local/lib/python3.5/dist-packages/catkin_pkg/condition.py", line 17, in
import pyparsing as pp
File "/home/casun/.local/lib/python3.5/site-packages/pyparsing/__init__.py", line 100
major: int
^
SyntaxError: invalid syntax
解决办法:
修改第一行提示的文件/usr/local/bin/catkin_create_pkg
sudo vim /usr/local/bin/catkin_create_pkg
文件内容如下:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from catkin_pkg.cli.create_pkg import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
将首行的#!/usr/bin/python3改为#!/usr/bin/python2,如下
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import re
import sys
from catkin_pkg.cli.create_pkg import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
然后运行创建功能包的命令就不会出错了。
问题的原因是:kinetic只用python2,然后我的系统默认的python3,但是修改软连接指向python2.7还是不行。查看源文件发现,需要修改第一行指定python环境