pycharm安装ROS各种问题记录

1.PyCharm调试Python工程

  • 新建catkin工作空间

mkdir -p ~/catkin_ws/src #建立源目录

cd ~/catkin_ws/src

catkin_init_workspace #初始化空间

cd ~/catkin_ws/

catkin_make #首次编译

echo “source ~/catkin_ws/devel/setup.bash” >> ~/.bashrc #使用工作空间

  • 需要重新打开终端,环境配置才能生效
  • 添加测试代码

cd ~/catkin_ws/src

git clone https://github.com/ros/ros_tutorials.git

ls

  • 或使用其他工具下载后,在上传到tools目录
  • 安装,在tools目录下

cd ~/tools
tar xfz pycharm-professional-2016.2.3.tar.gz #解压
cd pycharm-professional-2016.2.3
./pycharm.sh #按提示安装即可

1.1PyCharm里添加工程

  • 导入 rospy_tutorials 包,使之成为PyCharm的python工程。点击 Open Directory 按钮,在弹出的对话框中选择 ~/catkin_ws/src/ros_tutorials/rospy_tutorials/ 路径
p01
  • 点击 OK,工程将被创建
p02
  • 设置python2.7为PyCharm工程的Interpreter

  • PyCharm默认将Python 3.2设置为工程的interpreter,而ROS使用的是Python 2.7,这里需要设置一下,使用Python 2.7,否则无法运行ROS相关的Python库。如果默认是Python 2.7则不用修改

  • File 菜单 -> Settings 项,打开设置对话框,选择 Project Interpreter -> Python Interpreters

p03
  • 点击右边选框的加号,增加 Python 2.7 Interpreter,并将其设置为工程默认
p04
  • 调试代码

  • 先打开一个terminal,输入 roscore 命令启动ROS Master

  • 在PyCharm左边的 Project 树形框中,找到 talker.py 文件,打开。然后找到 “hello world” 所在的位置,修改为 “hello I’m yuanboshe”,并设置断点

p05
  • 保存后,右键左边的 talker.py 文件,弹出右键菜单,选择 Debug ‘talker’ 项
p06
  • 启动调试后,talker 程序就会运行,并会运行到断点处停下来
p07
  • 在下面的变量栏能够看到变量值。取消断点,按 F9 继续运行,将下面的显示窗口切换到 Console 窗口,能够看到修改后的信息

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fqdnDUbJ-1641276734368)(images/p08.jpg)]

  • 回到桌面,再开一个terminal窗口,输入 rosrun rospy_tutorials listener 命令,可以看到正确的监听消息

2.各种问题小记录

2.1 命令cmak_make错误信息

CMake Error at /opt/ros/noetic/share/catkin/cmake/empy.cmake:30 (message
Unable to find either executable ‘empy’ or Python module ‘em’… try
installing the package ‘python3-empy’

尝试解决办法:

1.pip install empy 或者 conda install empy等 无效果

-- Using CATKIN_DEVEL_PREFIX: /home/hyy/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/noetic
-- This workspace overlays: /opt/ros/noetic
-- Using PYTHON_EXECUTABLE: /home/hyy/anaconda3/envs/hyy/bin/python3
-- Using Debian Python package layout
-- Found PY_em: /home/hyy/anaconda3/envs/hyy/lib/python3.7/site-packages/em.py  
-- Using empy: /home/hyy/anaconda3/envs/hyy/lib/python3.7/site-packages/em.py
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/hyy/catkin_ws/build/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /home/hyy/anaconda3/envs/hyy/bin/python3 (found version "3.7.11") 
-- Found Threads: TRUE  
-- Using Python nosetests: /usr/bin/nosetests3
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.
CMake Error at /opt/ros/noetic/share/catkin/cmake/safe_execute_process.cmake:11 (message):
  execute_process(/home/hyy/anaconda3/envs/hyy/bin/python3
  "/opt/ros/noetic/share/catkin/cmake/parse_package_xml.py"
  "/opt/ros/noetic/share/catkin/cmake/../package.xml"
  "/home/hyy/catkin_ws/build/catkin/catkin_generated/version/package.cmake")
  returned error code 1
Call Stack (most recent call first):
  /opt/ros/noetic/share/catkin/cmake/catkin_package_xml.cmake:74 (safe_execute_process)
  /opt/ros/noetic/share/catkin/cmake/all.cmake:168 (_catkin_package_xml)
  /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:20 (include)
  CMakeLists.txt:58 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/hyy/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/hyy/catkin_ws/build/CMakeFiles/CMakeError.log".
Invoking "cmake" failed

后查资料发现通过更改环境位置可以使用:

catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

不过网上也有资料显示python3与ROS 兼容性不好,将其更改为python2更好,这里我应为更改完之后为出错,所以就没关。
更改完之后输入 catkin_make命令。

-- Using CATKIN_DEVEL_PREFIX: /home/hyy/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/noetic
-- This workspace overlays: /opt/ros/noetic
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Using Debian Python package layout
-- Using empy: /home/hyy/anaconda3/envs/hyy/lib/python3.7/site-packages/em.py
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/hyy/catkin_ws/build/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") 
-- Using Python nosetests: /usr/bin/nosetests3
-- catkin 0.8.10
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hyy/catkin_ws/build

2.2 rosrun rospy_tutorials listener 报错

File “/opt/ros/noetic/lib/python3/dist-packages/roslib/launcher.py”, line 42, in
import rospkg
ModuleNotFoundError: No module named ‘rospkg’

这里是因为安装了anconda,会将ubuntu默认的python启动顺序更改掉。
需要进行下面两个步骤:

conda install setuptools  #第一个命令

#安装完成之后,进行第二个命令

pip install -U rosdep rosinstall_generator wstool rosinstall six vcstools
#这条指令有时候会报错443,因为网络的问题,遇到之后重新再输入一遍就行。或者一劳永逸的办法就是更换安装源。

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值