Tiryoh / docker-ros2-desktop-vnc

🐳 Dockerfiles to provide HTML5 VNC interface to access Ubuntu Desktop + ROS 2
https://memoteki.net/archives/2955
Apache License 2.0
433 stars 85 forks source link

ModuleNotFoundError: No module named 'rclpy' when running Docker Image as PyCharm's remote Python interpreter #42

Closed mac137 closed 2 years ago

mac137 commented 2 years ago

Hello! Thanks for the wonderful Dockerfiles.

I was just wondering what I can do to make the Python interpreter from these docker images work as a remote Python interpreter in PyCharm? image

When I just try to run a python file main.py, let's say this one:

import sys
import numpy as np
import rclpy

I get this error in PyCharm's console:

1f229640f3d3:python -u /opt/project/main.py
Traceback (most recent call last):
  File "/opt/project/main.py", line 6, in <module>
    import rclpy
ModuleNotFoundError: No module named 'rclpy'

Process finished with exit code 1

However, when I manually append the missing python packages from ros:

import sys
sys.path.append("/opt/ros/foxy/lib/python3.8/site-packages")
import numpy as np
import rclpy

I get this error:

95eddbfd10a4:python -u /opt/project/main.py
Traceback (most recent call last):
  File "/opt/project/main.py", line 8, in <module>
    from rclpy.node import Node
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 41, in <module>
    from rclpy.client import Client
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/client.py", line 22, in <module>
    from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/impl/implementation_singleton.py", line 31, in <module>
    rclpy_implementation = _import('._rclpy')
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/impl/__init__.py", line 28, in _import
    return importlib.import_module(name, package='rclpy')
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: librclpy_common.so: cannot open shared object file: No such file or directory
The C extension '/opt/ros/foxy/lib/python3.8/site-packages/rclpy/_rclpy.cpython-38-aarch64-linux-gnu.so' failed to be imported while being present on the system. Please refer to 'https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-even-with-library-present-on-the-system' for possible solutions

Process finished with exit code 1

The same error occurs when I append RUN bash -c "source /opt/ros/foxy/setup.bash" to the Dockerfile.

it is clear that the PyCharm's interpreter is not properly sourced. Any idea how to fix this?

Tiryoh commented 2 years ago

Hi @maciej-3, thanks for your feedback. Sorry for my late responding. I had missed the notification.

The Dockerfile for this project is structured based on and inherits from https://github.com/fcwu/docker-ubuntu-vnc-desktop. I think the cause of this problem is that the startup.sh specified in the entrypoint is not executed.

https://github.com/fcwu/docker-ubuntu-vnc-desktop/blob/e4922ce92f945fc482994b7a0fd95ca5de7295b3/Dockerfile.amd64#L129

https://github.com/fcwu/docker-ubuntu-vnc-desktop/blob/e4922ce92f945fc482994b7a0fd95ca5de7295b3/rootfs/startup.sh

If there is a PyCharm setting that allows you to run a specific script when Docker is started, could you try that?

According to the PyCharm documentation, the Community Edition does not support remote development, so I may not be able to follow up in detail. https://www.jetbrains.com/help/pycharm/faq-about-remote-development.html#community

mac137 commented 2 years ago

Thanks @Tiryoh for your answer. I think there is a workaround using docker-compose as described here: https://youtrack.jetbrains.com/issue/PY-22909?_ga=2.214133204.2141338765.1646771596-890459913.1642868424&_gac=1.254324986.1645988977.Cj0KCQiA3-yQBhD3ARIsAHuHT65YbWqnHwALM__71tJaiYQzepJVePSwBDvh3BaO-YPB7WMAi2K1ROMaAlCREALw_wcB#comment=27-1963873