MATLAB: Error using ros.ros2.i​nternal.cr​eateOrGetL​ocalPython

custom messagepythonrosROS Toolboxros2

Hello,
Recently I encountered the following error when trying to call ros2genmsg. Anyone can help? Thanks in advance.
Error using ros.ros2.internal.createOrGetLocalPython (line 133)
Could not install the required Python packages: Looking in links:
/var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/argcomplete-1.10.0-py2.py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/flake8-3.7.8-py2.py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/flake8-blind-except-0.1.1.tar.gz
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/flake8_class_newline-1.6.0-py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/flake8_comprehensions-2.1.0-py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/flake8_docstrings-1.3.0-py2.py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/flake8_import_order-0.18.1-py2.py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/flake8-quotes-2.0.1.tar.gz
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/pytest-5.0.1-py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/pytest_cov-2.7.1-py2.py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/pytest_runner-5.1-py2.py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/pytest_repeat-0.8.0-py2.py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/pytest_rerunfailures-7.0-py2.py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/colcon_common_extensions-0.2.0-py3-none-any.whl
Processing /var/home/alex/opt/MATLAB/R2020a/sys/ros2/share/python/lark-parser-0.7.2.tar.gz
[31mERROR: Could not find a version that satisfies the requirement numpy (from versions: none)[0m
[31mERROR: No matching distribution found for numpy[0m
. Verify there is space on disk to create the packages and retry the command.
Error in ros2genmsg (line 53)
ros.ros2.internal.createOrGetLocalPython(); %ensure python is available
For reference,
>> pyenv
ans =
PythonEnvironment with properties:
Version: "3.8"
Executable: "/var/home/alex/miniconda3/envs/matlab/bin/python"
Library: "/var/home/alex/miniconda3/envs/matlab/lib/libpython3.8.so"
Home: "/var/home/alex/miniconda3/envs/matlab"
Status: NotLoaded
ExecutionMode: InProcess

Best Answer

Hello Alexander,
There is unfortunately an issue with the current documentation, which should be updated soon. Instead of Python 3.7+, you need exactly Python 3.7 to use ROS 2 custom messages or code generation with MATLAB. Once you install Python 3.7 and point MATLAB to use it with pyenv('Version', <executable path>), it should work.
-Cam