Python library compilation error (Python 3.9, MATLAB R2021b)

6 views (last 30 days)
Hello all,
I am trying to use a Python library from within MATLAB for Reinforcement Learning. I have followed all the instructions and I have the library correclty installed in my system, using Python 3.9.11, which is supported by MATLAB 2021b. pyenv instruction also shows a correct detection of Python from MATLAB command line. I have also all the needed pip packages installed:
PS C:\Users\alberto.tellaeche> pip list
Package Version
------------------ --------
cffi 1.15.0
cloudpickle 2.0.0
Cython 0.29.28
fasteners 0.17.3
glfw 2.5.1
gym 0.23.1
gym-notices 0.0.6
gym-robotics 0.1.0
imageio 2.16.1
importlib-metadata 4.11.3
mujoco-py 2.1.2.14
numpy 1.22.3
Pillow 9.0.1
pip 22.0.4
pycparser 2.21
pygame 2.1.2
setuptools 58.1.0
zipp 3.7.0
One of the packages installed using "pip install", needs to compile something. I have checked C++ compiled and it is in the path MATLAB looks for it.
When I call the library from MATLAB´s command window:
env = py.gym.make('FetchReach-v1')
I get the following compiling error:
Compiling C:\Python39\lib\site-packages\mujoco_py\cymj.pyx because it changed.
[1/1] Cythonizing C:\Python39\lib\site-packages\mujoco_py\cymj.pyx
running build_ext
building 'mujoco_py.cymj' extension
creating C:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder
creating C:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9
creating C:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9\Release
creating C:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9\Release\Python39
creating C:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9\Release\Python39\lib
creating C:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9\Release\Python39\lib\site-packages
creating C:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9\Release\Python39\lib\site-packages\mujoco_py
creating C:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9\Release\Python39\lib\site-packages\mujoco_py\gl
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Python39\lib\site-packages\mujoco_py -IC:\Users\alberto.tellaeche\.mujoco\mujoco210\include -IC:\Python39\lib\site-packages\numpy\core\include -I.\include -I.\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include -IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /TcC:\Python39\lib\site-packages\mujoco_py/gl/dummyshim.c /FoC:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9\Release\Python39\lib\site-packages\mujoco_py/gl/dummyshim.obj -fopenmp -w
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Python39\lib\site-packages\mujoco_py -IC:\Users\alberto.tellaeche\.mujoco\mujoco210\include -IC:\Python39\lib\site-packages\numpy\core\include -I.\include -I.\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include -IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /TcC:\Python39\lib\site-packages\mujoco_py\cymj.c /FoC:\Python39\lib\site-packages\mujoco_py\generated\_pyxbld_2.1.2.14_39_windowsextensionbuilder\temp.win-amd64-3.9\Release\Python39\lib\site-packages\mujoco_py\cymj.obj -fopenmp -w
Error using _msvccompiler>compile (line 403)
Python Error: CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual
Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
Error in build_ext>build_extension (line 529)
Error in build_ext>_build_extensions_serial (line 474)
Error in build_ext>build_extensions (line 449)
Error in old_build_ext>build_extensions (line 195)
Error in builder>build_extensions (line 149)
Error in build_ext>run (line 340)
Error in old_build_ext>run (line 186)
Error in dist>run_command (line 985)
Error in dist>run_commands (line 966)
Error in builder>_build_impl (line 249)
Error in builder>build (line 226)
Error in builder>load_cython_ext (line 110)
Error in builder><module> (line 504)
Error in __init__><module> (line 2)
Error in robot_env><module> (line 14)
Error in fetch_env><module> (line 3)
Error in __init__><module> (line 1)
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Error in <frozen importlib>_find_and_load_unlocked (line 986)
Error in <frozen importlib>_find_and_load (line 1007)
Error in <frozen importlib>_gcd_import (line 1030)
Error in __init__>import_module (line 127)
Error in registration>load (line 55)
Error in registration>make (line 139)
Error in registration>make (line 520)
Error in registration>make (line 676)
>>
I have googled for this problem, and although it seems common, no thread gives a proper solution, and even less taking MATLAB into account.
Could anyone give a possible solution for this issue.
Thank you all very much in advance.

Accepted Answer

Eric Delgado
Eric Delgado on 19 Sep 2022
Hi @Alberto Tellaeche, I was dealing with a similar issue - numpy was the lib that was not running. The solution was create a new env using conda.
Anaconda prompt (or similar):
conda create -n numpy python=3.9 numpy -c conda-forge -y
Matlab (pointer to the python.exe of the new env):
pyenv('Version', 'C:\Users\eric\anaconda3\envs\numpy\python.exe')

More Answers (0)

Categories

Find more on MATLAB Compiler SDK in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!