紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
rospy路径出错
-
运行程序时需要import rospy,发现环境中的rospy路径在/dist-packages中,而程序是在/site-packages中找的
(base) xxx@xxx-virtual-machine:~$ python Python 3.8.8 (default, Apr 13 2021, 19:58:26) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import rospy Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module> from .client import spin, myargv, init_node, \ File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in <module> import roslib File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 53, in <module> import roslib.stacks # noqa: F401, I100 File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/stacks.py", line 45, in <module> import roslib.packages File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/packages.py", line 48, in <module> from catkin.find_in_workspaces import find_in_workspaces as catkin_find File "/opt/ros/melodic/lib/python2.7/dist-packages/catkin/find_in_workspaces.py", line 39, in <module> from catkin_pkg.packages import find_packages ImportError: cannot import name 'find_packages' from 'catkin_pkg.packages' (/home/xxx/anaconda3/lib/python3.8/site-packages/catkin_pkg/packages.py) >>> [1]+ 已停止 python (base) xxx@xxx-virtual-machine:~$ pip install rospy Requirement already satisfied: rospy in /opt/ros/melodic/lib/python2.7/dist-packages (1.14.13)
通过检索知道:
如果是系统自带的python,会使用dist-packages目录;
如果手动安装python,会直接使用目录site-packages
参考:https://blog.csdn.net/cc1949/article/details/78286224
请问这种情况应如何解决呢?
-
@1687028512 没太理解你的意思哈,看你的错误时rospy导入时候发生错误,错误原因在catkin_pkg,也尝试降低以下catkin_pkg的版本试试,可能要和rospy匹配。
-
-
@1687028512 没太理解你的意思哈,看你的错误时rospy导入时候发生错误,错误原因在catkin_pkg,也尝试降低以下catkin_pkg的版本试试,可能要和rospy匹配。
尝试降低catkin_pkg版本
pip3 install catkin-pkg==0.4.16
得到
(base) xxx@xxx-virtual-machine:~$ pip3 install catkin-pkg==0.4.16 Collecting catkin-pkg==0.4.16 Downloading catkin_pkg-0.4.16-py3-none-any.whl (74 kB) |████████████████████████████████| 74 kB 311 kB/s Requirement already satisfied: docutils in /home/xxx/anaconda3/lib/python3.8/site-packages (from catkin-pkg==0.4.16) (0.17.1) Requirement already satisfied: pyparsing in /home/xxx/anaconda3/lib/python3.8/site-packages (from catkin-pkg==0.4.16) (2.4.7) Requirement already satisfied: python-dateutil in /home/xxx/anaconda3/lib/python3.8/site-packages (from catkin-pkg==0.4.16) (2.8.1) Requirement already satisfied: six>=1.5 in /home/xxx/anaconda3/lib/python3.8/site-packages (from python-dateutil->catkin-pkg==0.4.16) (1.15.0) Installing collected packages: catkin-pkg Attempting uninstall: catkin-pkg Found existing installation: catkin-pkg 0.4.24 Uninstalling catkin-pkg-0.4.24: Successfully uninstalled catkin-pkg-0.4.24 Successfully installed catkin-pkg-0.4.16
重新执行python命令,报错解决。
参考
https://blog.csdn.net/weixin_41560777/article/details/122744467
非常感谢小鱼的及时解答!上周因为一些事情暂停了项目,没有及时回复,在这里说声抱歉~我又肥来啦~
-