我在cmakelists.txt中启用了python函数,使用catkin_make时遇到了一个奇怪的问题,如下所示:
cmake_minimum_required(VERSION 3.0.2)
project(transmit)
set(Python3_INCLUDE_DIRS "/usr/include/python3.6m")
set(Python3_LIBRARIES "/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so")
set(PYTHON_EXECUTABLE "/usr/bin/python3.6")
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
sensor_msgs
std_msgs
)
catkin_package(
CATKIN_DEPENDS roscpp rospy sensor_msgs std_msgs
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${Python3_INCLUDE_DIRS}
)
add_executable(transmit src/transmit.cpp)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${Python3_LIBRARIES}
)
执行catkin_make后,终端报错如下:
Traceback (most recent call last):
File "/opt/ros/melodic/bin/catkin_make", line 13, in <module>
from catkin.builder import apply_platform_specific_defaults # noqa: E402
File "/opt/ros/melodic/lib/python2.7/dist-packages/catkin/builder.py", line 54, in <module>
from catkin_pkg.packages import find_packages
File "/usr/local/lib/python3.6/dist-packages/catkin_pkg/packages.py", line 38, in <module>
from .package import _get_package_xml
File "/usr/local/lib/python3.6/dist-packages/catkin_pkg/package.py", line 44, in <module>
from catkin_pkg.condition import evaluate_condition
File "/usr/local/lib/python3.6/dist-packages/catkin_pkg/condition.py", line 17, in <module>
import pyparsing as pp
File "/usr/local/lib/python3.6/dist-packages/pyparsing/__init__.py", line 100
major: int
^
SyntaxError: invalid syntax
好像是一个python官方包有语法错误,很奇怪,怎么解决这个问题呢?
2条答案
按热度按时间nszi6y051#
您使用的是ROS Melodic,它默认支持Python2.7。您尝试使用的软件包是为Python3编写的,但它试图导入为Python2.7脚本。要解决这个问题,您需要找到该软件包的Python2.7版本,或者将所有内容升级到ROS Noetic,它针对Python3.x。
从技术上讲,第二个选项是正确的,因为您真的不应该再使用Python2了。
ddrv8njm2#
pyparser 2.4.7与Python 2是兼容的。