Coppeliasim 4.3.0 [Windows] can't handle numpy import

Report crashes, strange behaviour, or apparent bugs
Post Reply
obasic
Posts: 5
Joined: 15 Jul 2020, 05:40

Coppeliasim 4.3.0 [Windows] can't handle numpy import

Post by obasic »

First of all, I really commend the massive efforts put into the recent coppeliasim update.

Specifically, the support for python is really a nice one. However, it's throws error for all imports built on numpy.

Being that almost all robotics and ML libraries are built on numpy, utilizing the full power of python with coppeliasim will be crippled without flexible importing of libraries.

Code: Select all

 ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:628: 
      [/nonThreadedChildScript], line 4, in sysCall_init
      File "defaultPython\envs\coppeliasim_py\lib\site-packages\numpy\__init__.py", line 150, in <module>
        from . import core
      File defaultPython\envs\coppeliasim_py\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
        raise ImportError(msg)
    ImportError: 
    
    IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
    
    Importing the numpy C-extensions failed. This error can happen for
    many reasons, often due to issues with your setup or how NumPy was
    installed.
    
    We have compiled some common reasons and troubleshooting tips at:
    
        https://numpy.org/devdocs/user/troubleshooting-importerror.html
    
    Please note and check the following:
    
      * The Python version is: Python3.7 from "defaultPython\envs\coppeliasim_py\python.exe"
      * The NumPy version is: "1.21.2"
    
    and make sure that they are the versions you expect.
    Please carefully study the documentation linked above for further help.
    
    Original error was: DLL load failed: The specified module could not be found.
    
    
    stack traceback:
        [C]: in function 'error'
        ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:628: in function 'handleErrors'
        ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:647: in function 'handleRemote'
        ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:415: in function 'sysCall_actuation'


Please kindly look into it.


Kind regards

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Coppeliasim 4.3.0 [Windows] can't handle numpy import

Post by coppelia »

Hello,

can you provide a minimalistic example? I suspect your Python installation might be broken.
Following works fine here (python 3.8, CoppeliaSim V4.3.0, rev0):

Code: Select all

#python
import numpy as np
def sysCall_init():
    a=np.arange(15).reshape(3,5)
    print(a)
Also make sure to re-download CoppeliaSim V4.3 if you did before Feb. 1, 2022, there was a small bug. Alternatively, you can fix the file lua/pythonWrapper.lua around line 306, replacing:

Code: Select all

                            local p1=string.find(msg,'File "<string>"')
                            local p2=string.find(msg,'File "<string>"',p1+1)
                            msg="\n"..string.sub(msg,p2)
                            local obj=sim.getObject('.',{noError=true})
                            if obj>=0 then
                                msg=msg:gsub('File "<string>"',"["..sim.getObjectAlias(obj,1).."]")
                            end
with:

Code: Select all

                            local p1=string.find(msg,'File "<string>"')
                            if p1 then
                                msg="\n"..string.sub(msg,p1)
                                local obj=sim.getObject('.',{noError=true})
                                if obj>=0 then
                                    msg=msg:gsub('File "<string>"',"["..sim.getObjectAlias(obj,1).."]")
                                end
                            end
Cheers

obasic
Posts: 5
Joined: 15 Jul 2020, 05:40

Re: Coppeliasim 4.3.0 [Windows] can't handle numpy import

Post by obasic »

Thanks for your swift response.

Your pointers were really helpful.

I tried all other suggestions except trying another python installation, because, I had earlier tried creating new anaconda environments with various python versions (3.5, 3.6, 3.7 and 3.8) before tendering my submission.

Inline with your suggestions, I eventually got it fixed with a fresh 64bit python installation (not anaconda).

Bringing me to the conclusion that the culprit might have been my 32bit anaconda.

Thanks once again.

kind regard

Post Reply