Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to open a MATLAB engine session on Windows #167

Closed
wangjie212 opened this issue Feb 5, 2020 · 11 comments · Fixed by #236
Closed

Failed to open a MATLAB engine session on Windows #167

wangjie212 opened this issue Feb 5, 2020 · 11 comments · Fixed by #236

Comments

@wangjie212
Copy link

Hello,

When calling MSession(), I get the following error on Windows:
ERROR: MEngineError("Failed to open a MATLAB engine session")
in MSession at MATLAB\cVrxc\src\engine.jl:23.

I'm using Matlab R2019b 64 bits. I can start Matlab normally.
I have set the env variable MATLAB_HOME and runned matlab -regserver in a Command Prompt as Administrator.

Anyone knows how to fix this?

@musm
Copy link
Collaborator

musm commented Feb 5, 2020

which julia version and platform?

@wangjie212
Copy link
Author

Julia 1.2.0 Windows10

@ronubi
Copy link

ronubi commented Feb 7, 2020

Without explicitly calling MSession, can you just do

mat"ver"

to see if Julia will connect to the Matlab engine?

@wangjie212
Copy link
Author

Without explicitly calling MSession, can you just do

mat"ver"

to see if Julia will connect to the Matlab engine?

It reports the error:
MEngineError("failed to open MATLAB engine session")

@musm
Copy link
Collaborator

musm commented Feb 10, 2020

very odd.

@jacob-roth
Copy link

jacob-roth commented Oct 19, 2023

I had to do the following (which is manually/hardcoded for R2020b)

  1. clone my version https://github.com/jacob-roth/MATLAB.jl.git
  2. add push!(LOAD_PATH,"C:\\Users\\roth0674\\git\\MATLAB.jl") to AppData/Local/Programs/Julia-1.x.x/etc/julia/startup.jl and open REPL
  3. from REPL, set ENV["MATLAB_ROOT"] = "C:\Program Files\MATLAB\R2020b\" (you will have to move it to this location if you dont want to edit my fork)
  4. ] add "C:\path\to\cloned\MATLAB.jl"
  5. ] build MATLAB
  6. using MATLAB

@VoSiLk
Copy link

VoSiLk commented Feb 11, 2025

Hi, the above mentioned workaround does not work for me. I still get the same error message. Is there another workaround so I can run MATLAB 2020b from julia while in parallel MATLAB2022b installed on my machine?

@tqml
Copy link
Collaborator

tqml commented Feb 14, 2025

Hi @VoSiLk !
What operating system and julia version are you using?

What you could try (if not already done):

  1. Remove the MATLAB julia package
  2. delete existing compiled for MATLAB in the .julia/compiled/<version>/MATLAB directory (the .julia dir should be in %HOMEPATH%\.julia\ or ~/.julia)
  3. set the environment variable MATLAB_ROOT (or MATLAB_HOME) to the version you want to use. To check, the resolved path will be $MATLAB_ROOT/bin/<os-arch>/matlab[.exe] so check if this is the correct path (<os-arch> dependes on your system, e.g. win64)
  4. install MATLAB.jl again
  5. Check that the correct path was used. E.g. try the following julia code: using MATLAB; println(MATLAB.matlab_libpath)
    For me this prints "/Applications/MATLAB_R2023b.app/bin/maca64" (on macos)
  6. If the version is correct, check if MATLAB.jl works

@tqml
Copy link
Collaborator

tqml commented Feb 14, 2025

One more thing: If you're on Windows, there seems to be an extra step.
The correct MATLAB "server" version must be registered with windows. This should happen automatically at install but if multiple versions are installed this might be the issue

  1. Open a new MATLAB window as administrator (with the version you want to use)
  2. In MATLAB run !matlab -regserver
  3. Close the MATLAB window

The version of MATLAB you opened, should now be the "default" version according to Windows.
So ensure, that this version and the one that MATLAB.jl uses, are the same.

Link to MATLAB docs:

@VoSiLk
Copy link

VoSiLk commented Feb 14, 2025

Thanks for your help.

The extra step:

  1. Open a new MATLAB window as administrator (with the version you want to use)
  2. In MATLAB run !matlab -regserver
  3. Close the MATLAB window

before

  1. Remove the MATLAB julia package
  2. Delete existing compiled for MATLAB in the .julia/compiled//MATLAB directory (the .julia dir should be in %HOMEPATH%.julia\ or ~/.julia)
  3. set the environment variable MATLAB_ROOT (or MATLAB_HOME) to the version you want to use. To check, the resolved path will be $MATLAB_ROOT/bin//matlab[.exe] so check if this is the correct path ( dependes on your system, e.g. win64)
  4. install MATLAB.jl again
  5. Check that the correct path was used. E.g. try the following julia code: using MATLAB; println(MATLAB.matlab_libpath)
    For me this prints "/Applications/MATLAB_R2023b.app/bin/maca64" (on macos)
  6. If the version is correct, check if MATLAB.jl works

has done the trick :)

My OS is Win11.

@tqml
Copy link
Collaborator

tqml commented Feb 14, 2025

Perfect! Thanks for trying (don't have a windows machine to test this) :)

I will push an update the error/help message

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

Successfully merging a pull request may close this issue.

6 participants