Open kangpyo opened 3 years ago
Hm. That looks like the “matlab” package isn’t installed in Python. I thought I had it set up so it would do that automatically, but looks like that’s not the case.
I’m not at a computer right now to try it, but you can try
using Conda
Conda.add(“matlab”)
Or if that doesn’t work, try
Conda.pip(“install”, “matlab”)
I’ll try to get the automated setup working within the next couple of days though.
it shows this error julia> Conda.add(matlab) ERROR: UndefVarError: matlab not defined Stacktrace: [1] top-level scope at none:1
julia> Conda.pip(“install”, “matlab”) ERROR: syntax: invalid character "“" near column 11
in my computer, python seems okay as it doesn't show any error to "import matlab" it happened to Julia.
I think I found what causes this problem.
the code in the shearedmatlabengine
function init() py""" import matlab.engine import numpy as np """ end
might need to be fixed like this? function init() space here-> py""" space here-> import matlab.engine space here-> import numpy as np """ end
That shouldn't make a difference, Julia isn't whitespace sensitive. That part is unindented to get around a bug in the Julia syntax highlighter that causes it to highlight everything after an indented string macro call as part of that string
So I think I might have a path forward. Not sure how I'm going to automate this, but this should at least work for you.
In Julia:
julia> ENV["PYTHONPATH"]
copy the path (with the string quotes)
in MATLAB:
>> cd (fullfile(matlabroot,'extern','engines','python'))
>> py = fullfile([paste the path here], "python.exe")
>> system(py + " setup.py install")
and that should be enough to get it working. I hope. I just tried this out on my other computer and it worked.
I have been trying to implement this code. I have installed Matlab 2019b which was downgrade to Matlab 2020a due to compatibility of MATLAB engine API. I have installed python 3.9 and pycharm. the environment set to MATLAB home. but I'm still receiving the error message.
I deleted the package in Julia and reinstalled again. i added "sys.path.append("matlab19bPy36")" and still get the same error message.
what might be my problem? can you help me?
Error from Julia InitError: PyError ($(Expr(:escape, :(ccall(#= C:\Users\mitadm.julia\packages\PyCall\BcTLp\src\pyeval.jl:38 =# @pysym(:PyEval_EvalCode), PyPtr, (PyPtr, PyPtr, PyPtr), o, globals, locals))))) <class 'ModuleNotFoundError'> ModuleNotFoundError("No module named 'matlab'") File "C:\Users\mitadm.julia\packages\PyCall\BcTLp\src\pyeval.jl", line 1, in
const Py_single_input = 256 # from Python.h
during initialization of module SharedMATLABEngine in _handle_error at PyCall\BcTLp\src\exception.jl:83 in pyerr_check at PyCall\BcTLp\src\exception.jl:66 in pyerr_check at PyCall\BcTLp\src\exception.jl:62
Error from python Traceback (most recent call last): File "C:\work\matlab19bPy37\Lib\site-packages\matlab\engine__init.py", line 45, in
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64 qbz5n2kfra8p0\lib\importlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'matlabengineforpython3_7'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\work\matlab19bPy37\Lib\site-packages\matlab\engine__init.py", line 61, in
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64 qbz5n2kfra8p0\lib\importlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 670, in _load_unlocked
File "", line 583, in module_from_spec
File "", line 1043, in create_module
File "", line 219, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:/Users/mitadm/PycharmProjects/pythonProject/main.py", line 25, in
import matlab.engine
File "C:\work\matlab19bPy37\Lib\site-packages\matlab\engine__init__.py", line 64, in
'MathWorks Technical Support for assistance: %s' % e)
OSError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: DLL load failed: The specified module could not be found.
Process finished with exit code 1