Skip to content
This repository has been archived by the owner on Apr 4, 2020. It is now read-only.

Error with 'import scilab2py' #12

Open
t-d-67 opened this issue Mar 22, 2018 · 21 comments
Open

Error with 'import scilab2py' #12

t-d-67 opened this issue Mar 22, 2018 · 21 comments

Comments

@t-d-67
Copy link

t-d-67 commented Mar 22, 2018

I'm a newbie to Python but have experience in MATLAB/Scilab. I'm creating a mathematical model in Scilab, but the input data is generated from a Python (2.7) code. As a result, I'm trying to make use of the the scilab2py module in order to run Scilab from inside Python to allow the process to be much simpler.

I installed all the required Python modules for scilab2py (i.e. Scipy, Numpy) and have Scilab installed in my PATH (following all the instructions in http://blink1073.github.io/scilab2py/source/installation.html), so I installed scilab2py using

pip install scilab2py

which it says was successful. However, if I enter Python and try

import scilab2py

I am met with the following error:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import scilab2py
  File "C:\Python27\lib\site-packages\scilab2py\__init__.py", line 46, in <module>
    lib1 = ctypes.CDLL(os.path.join(basepath, 'core', 'libmmd.dll'))
  File "C:\Python27\lib\ctypes\__init__.py", line 366, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

Does anyone know how to fix this error? Or perhaps know where I am going wrong with implementation?

Thanks in advance.

@hchesser
Copy link

I am getting the same error on a Windows 10, Anaconda3 (Python 3.5) installation. Installed with pip command.

I have set the Path environment variable to include the Scilab 5.5.2\bin directory...

@hchesser
Copy link

hchesser commented May 16, 2018

Actually I found the solution for this on the oct2py repo. The code is looking for dlls no longer included with numpy. So you have to use a try/except block in the init.py file around line 50 like this :

comment out the following lines:

lib1 = ctypes.CDLL(os.path.join(basepath, 'core', 'libmmd.dll'))
lib2 = ctypes.CDLL(os.path.join(basepath, 'core', 'libifcoremd.dll'))

def handler(sig, hook=thread.interrupt_main):
    hook()
    return 1

routine = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_uint)(handler)
ctypes.windll.kernel32.SetConsoleCtrlHandler(routine, 1)

add the following lines:

try: 
    lib1 = ctypes.CDLL(os.path.join(basepath, 'core', 'libmmd.dll'))
    lib2 = ctypes.CDLL(os.path.join(basepath, 'core', 'libifcoremd.dll'))

    def handler(sig, hook=thread.interrupt_main):
        hook()
        return 1

    routine = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_uint)(handler)
    ctypes.windll.kernel32.SetConsoleCtrlHandler(routine, 1)
except Exception:
    pass

@simon-zumbrunnen
Copy link

I'm using Anaconda 5.2 (Python 3.6.5). For me the two DLL's can be found under: {anaconda_path}/Library/bin

So i changed the following two lines:

lib1 = ctypes.CDLL(os.path.join(basepath, 'core', 'libmmd.dll'))
lib2 = ctypes.CDLL(os.path.join(basepath, 'core', 'libifcoremd.dll'))

to:

lib1 = ctypes.CDLL(os.path.join(os.path.split(sys.executable)[0], 'Library', 'bin', 'libmmd.dll'))
lib2 = ctypes.CDLL(os.path.join(os.path.split(sys.executable)[0], 'Library', 'bin', 'libifcoremd.dll'))

The easiest way to fix this would be to combine it with the try/except. For example:

try: 
    lib1 = ctypes.CDLL(os.path.join(basepath, 'core', 'libmmd.dll'))
    lib2 = ctypes.CDLL(os.path.join(basepath, 'core', 'libifcoremd.dll'))
    . . .
except Exception:
    lib1 = ctypes.CDLL(os.path.join(os.path.split(sys.executable)[0], 'Library', 'bin', 'libmmd.dll'))
    lib2 = ctypes.CDLL(os.path.join(os.path.split(sys.executable)[0], 'Library', 'bin', 'libifcoremd.dll'))

@blink1073 Would you like me to create a pull request, or do you want to fix it yourself?

Thanks for the package by the way. I have yet to try it though.

@blink1073
Copy link
Owner

@seimsel, PRs are always appreciated 😉

@davegutz
Copy link

When I implement these different fixes in windows I end up with another problem where scilab2py cannot find scilab in anyway at all. Scilab runs from cmd line as required by install instructions to test the PATH. The messages are all of the nature "raise Scilab2PyError('Could not find function named %s' % name)." Did you encounter this? It also happens to me in Linux as well as Win. Commands to reproduce:
from scilab2py import Scilab2Py
sci = Scilab2Py()
x = sci.zeros(3,3)

@simon-zumbrunnen
Copy link

Yes I have this problem too. I described what I think is the problem in Issues #13 and #14. I have no solution yet though.

@davegutz
Copy link

The issues 13 & 14 you describe above seems that Scilab 6 is working but not communicating correctly with python. I reverted to Scilab 5.5.2 and it now works.

@mentablack
Copy link

I am also having this problem
Iam on windows 10 64 bit usng scilab 5.5.2 and python 3.6
when importing scilab2py it gives an error

OSError Traceback (most recent call last)
in ()
----> 1 import scilab2py
C:\Users\Emman\Anaconda3\lib\site-packages\scilab2py_init_.py in ()
44 """
45 basepath = imp.find_module('numpy')[1]
---> 46 lib1 = ctypes.CDLL(os.path.join(basepath, 'core', 'libmmd.dll'))
47 lib2 = ctypes.CDLL(os.path.join(basepath, 'core', 'libifcoremd.dll'))
48
C:\Users\Emman\Anaconda3\lib\ctypes_init_.py in init(self, name, mode, handle, use_errno, use_last_error)
346
347 if handle is None:
--> 348 self._handle = _dlopen(self._name, mode)
349 else:
350 self._handle = handle

OSError: [WinError 126] The specified module could not be found

but when I follow the fixes above it also gives an error
Scilab not found. Please see documentation at:
http://blink1073.github.io/scilab2py/source/installation.html

@mentablack
Copy link

Following the Scilab Path Installation using this command

setx PATH "%PATH%;<C:\Program Files\scilab-5.5.2\bin>"

C:\WINDOWS\system32>setx PATH "%PATH%;<C:\Program Files\scilab-5.5.2\bin>"
WARNING: The data being saved is truncated to 1024 characters.
SUCCESS: Specified value was saved.

@mentablack
Copy link

I was able to call Scilex from the CMD
by going into the cmd's properties and changing its Start in to
the bin folder in scilab

@mentablack
Copy link

import scilab2py

Scilab not found. Please see documentation at:
http://blink1073.github.io/scilab2py/source/installation.html

already run this while setting the cmd to run as administrator and resulted to

C:\WINDOWS\system32>setx PATH "%PATH%;<C:\Program Files\scilab-5.5.2\bin>"

SUCCESS: Specified value was saved.

still it didnt work

@mentablack
Copy link

mentablack commented Oct 26, 2018 via email

@blink1073
Copy link
Owner

I'm not sure how to work around the change in numpy, so for now I wrapped the whole thing in a try/catch block. In your case, that means you won't be able to interrupt using Ctrl+C, but otherwise scilab2py should work. Please pip install -U scilab2py to pick up 0.6.2.

@mentablack
Copy link

Still has an error after I installed scilab2py using pip install -U scilab2py

from scilab2py import scilab

Scilab not found. Please see documentation at:
http://blink1073.github.io/scilab2py/source/installation.html
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name 'scilab' from 'scilab2py' (C:\Users\Emman\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scilab2py_init_.py)

@mentablack
Copy link

Thank you everyone for the help
I fixed the problem! I manually set the path by going the " Edit the System Environments" in windows10 and added the Scilab path there! I can open Scilab in the CMD now! that was my problem

@mentablack
Copy link

Will scilab2py run on a Raspberry Pi ?

@blink1073
Copy link
Owner

It should, but I've never tried ;).

@mentablack
Copy link

@blink1073 I sincerely want to ask a question regarding Scilabmagic

Can i extract a variable from scilab and move it to python
or vice versa ? I have been reading the scilabmagic.py for examples but i failed to display or get a variable from scilab.

What Iam trying to do Using a basic XCOS block diagram
simply a step response that is feed to an "To workspace block" and naming it as a variable " Stepout2Python" Instead of displaying the graph on Scilab I want to display it in python .

Is this possible?

@davegutz
Copy link

davegutz commented Dec 31, 2018 via email

@simon-zumbrunnen
Copy link

I agree. XCos on Windows with Scilab 6.0 is horrible.

@mentablack
Copy link

mentablack commented Dec 31, 2018

I'am using Scilab 5.5.2 it works perfectly fine like u said and was not successful with Scilab 6

I found this pdf using python and xcos together but im having errors also
http://www.cnm.es/~mdei/pythonize_yourself/pythonize_yourself_old01.pdf
Happy New year everyone sorry for making this a somewhat discussion thread

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants