ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

ROS2 : ModuleNotFoundError: No module named ‘rclpy._rclpy’.

asked 2020-06-16 12:34:44 -0600

BadrMt gravatar image

updated 2020-06-18 02:38:18 -0600

Hi all,

I’m new in using linux and i’ve been trying to run ros 2 on linux 20.04. I’ve followed the “Installing ROS 2 on Linux” tutorial : https://index.ros.org/doc/ros2/Installation/Foxy/Linux-Install-Binary/

All have been fine until i run the command

ros2 run demo_nodes_py listener

and i get the following traceback :

Traceback (most recent call last):
File “/home/moutalib/ros2_foxy/ros2-linux/lib/demo_nodes_py/listener”, line 11, in
load_entry_point(‘demo-nodes-py==0.9.3’, ‘console_scripts’, ‘listener’)()
File “/home/moutalib/anaconda3/lib/python3.7/site-packages/pkg_resources/ init .py”, line 490, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File “/home/moutalib/anaconda3/lib/python3.7/site-packages/pkg_resources/ init .py”, line 2854, in load_entry_point
return ep.load()
File “/home/moutalib/anaconda3/lib/python3.7/site-packages/pkg_resources/ init .py”, line 2445, in load
return self.resolve()
File “/home/moutalib/anaconda3/lib/python3.7/site-packages/pkg_resources/ init .py”, line 2451, in resolve
module = import (self.module_name, fromlist=[‘ name ’], level=0)
File “/home/moutalib/ros2_foxy/ros2-linux/lib/python3.8/site-packages/demo_nodes_py/topics/listener.py”, line 16, in
from rclpy.node import Node
File “/home/moutalib/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/node.py”, line 41, in
from rclpy.client import Client
File “/home/moutalib/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/client.py”, line 22, in
from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy
File “/home/moutalib/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/impl/implementation_singleton.py”, line 31, in
rclpy_implementation = _import(’._rclpy’)
File “/home/moutalib/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/impl/ init .py”, line 27, in _import
return importlib.import_module(name, package=‘rclpy’)
File “/home/moutalib/anaconda3/lib/python3.7/importlib/ init .py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named ‘rclpy._rclpy’

I have tried to look on other topics but couldnt find a solution that works for me. I would be grateful if anyone can help me debug this problem. Thank you.

edit retag flag offensive close merge delete

Comments

I’ve followed the “Installing ROS 2 on Linux” tutorial [..]

which one? Always include a link.

gvdhoorn gravatar image gvdhoorn  ( 2020-06-16 13:17:37 -0600 )edit

In the future a much more helpful error message should be shown: https://github.com/ros2/rclpy/pull/580

Dirk Thomas gravatar image Dirk Thomas  ( 2020-06-20 11:07:14 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-06-18 11:00:01 -0600

johnconn gravatar image

updated 2020-06-18 11:00:21 -0600

your stack trace looks extremely suspect to me, it looks as if you built ros2 with python3.8 but it seems you're in a conda environment that is using python3.7? I may be wrong about the environment, but you definitely want to make sure you're using a single python version

If we look at the last two lines of the stack trace

File “/home/moutalib/anaconda3/lib/python3.7/importlib/ init .py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named ‘rclpy._rclpy’

The python 3.7 importlib is going to be looking in all of the python3.7 install paths for rclpy, but it will not find it because rclpy was installed with python3.8

edit flag offensive delete link more

Comments

Hello, Thank you for your response. Can you tell me what to do in order to have a single python version ? Should i uninstall conda ?

BadrMt gravatar image BadrMt  ( 2020-06-19 01:59:54 -0600 )edit
1

make sure your conda environment is deactivated using the command conda deactivate. Then things should work. Unfortunately up to ros2 eloquent (and I assume foxy) the build system will only ever look at your system python, and wouldn't work with virtual environments or conda.

johnconn gravatar image johnconn  ( 2020-06-19 09:31:34 -0600 )edit

Thank you very much. This solve dmy problem and made me realise an important detail that i was missing about why did i have (base) written before my terminal line.

BadrMt gravatar image BadrMt  ( 2020-06-20 05:34:02 -0600 )edit

i'm glad we could get this resolved! Could you click the checkmark to indicate this answer solved your issue?

johnconn gravatar image johnconn  ( 2020-06-20 10:15:47 -0600 )edit

I have the same issue but when I type conda deactivate, it says that conda: command not found Can you help me with this?

dm gravatar image dm  ( 2021-10-02 14:18:41 -0600 )edit

check ~/.bashrc if conda command is allowed

Roy Lim gravatar image Roy Lim  ( 2023-07-10 21:33:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-06-16 12:32:15 -0600

Seen: 23,535 times

Last updated: Jun 18 '20