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

MATLAB Login problems persist #105

Closed
GlascherLab opened this issue Nov 20, 2024 · 21 comments
Closed

MATLAB Login problems persist #105

GlascherLab opened this issue Nov 20, 2024 · 21 comments
Assignees
Labels
answered Issue has been answered bug Something isn't working question Further information is requested

Comments

@GlascherLab
Copy link

Summary

I have installed a miniconda python setup on a Macbookd Pro (Apple M3 Silicon chipset) and a MATLAB R2024b installed and added to my system path. Following this descriptions, I ran

cd /Applications/MATLAB_R2024b.app/extern/engines/python/; python setup.py install

and then ued miniconda's pip to install jupyter-matlab-proxy and jupyterlab

pip install jupyter-matlab-proxy; pip install jupyterlab

When I choose the MATLAB kernel in the Laucher, I get to the MATLAB login page, where I entered my credentials using the Online License Manager for individaul licenses. I then get

Error connecting to MATLAB. Check the status of MATLAB by clicking the "Open MATLAB" button. Retry after ensuring MATLAB is running successfully

when I enter any command. Clicking on "Open MATLAB" I see

Status: not running
Licensing: Online LIcense Manager (login name)
Authenticated (wiht a green chekcmark)
Error: Online Licence Manager failed
Error Codes:
License Manager Error 4410
License Manager Error 4410
Invalid security token. (Status code: Unauthorized)

Any hints on how to solve this isseu would be highly appreciated.

Thanks.

PS: The throbleshooting scripts alerts me that Python is not installed. However, I rand the script with miniconda Python as well as with my other homebrew Python installation. Not sure if this is somehow related ...

Browser(s) used

Chrome

Issue found in

MATLAB Kernel

Script output

17:28 $ python troubleshooting.py


                                                                   MATLAB

matlab - /Applications/MATLAB_R2024b.app/bin/matlab OK


                                                              matlab-proxy-app

matlab-proxy-app - /opt/homebrew/bin/matlab-proxy-app OK


                                                                  Jupyter

jupyter - /opt/homebrew/bin/jupyter OK


                                                         Python and pip executables

python - None X
Recommendation: python is not installed. Please install python.

pip - /opt/homebrew/bin/pip OK

pip 24.3.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)

python3 - /opt/homebrew/bin/python3 OK

Python 3.11.10


                                                               OS information

Darwin
23.5.0
macOS-14.5-arm64-arm-64bit
uname_result(system='Darwin', node='synapse.local', release='23.5.0', version='Darwin Kernel Version 23.5.0: Wed May 1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030', machine='arm64')


                                                             Conda information

conda - None


                                                             Installed packages

/bin/sh: python: command not found


                                                         Jupyter server extensions

Config dir: /Users/glaescher/.jupyter

Config dir: /opt/homebrew/Cellar/jupyterlab/4.3.1/libexec/etc/jupyter
jupyter_lsp enabled
- Validating jupyter_lsp...
jupyter_lsp 2.2.5 OK
jupyter_server_terminals enabled
- Validating jupyter_server_terminals...
jupyter_server_terminals 0.5.3 OK
jupyterlab enabled
- Validating jupyterlab...
jupyterlab 4.3.1 OK
notebook enabled
- Validating notebook...
notebook 7.0.7 OK
notebook_shim enabled
- Validating notebook_shim...
notebook_shim OK

Config dir: /usr/local/etc/jupyter

JupyterLab v4.3.1
/opt/homebrew/Cellar/jupyterlab/4.3.1/libexec/share/jupyter/labextensions
jupyterlab_pygments v0.3.0 enabled OK (python, jupyterlab_pygments)
@jupyter-notebook/lab-extension v7.0.7 enabled OK


                                                           Environment variables

@GlascherLab GlascherLab added bug Something isn't working needs-triage labels Nov 20, 2024
@prabhakk-mw
Copy link
Member

Hi @GlascherLab

4410 usually implies that your MathWorks account is not linked to the MATLAB release that's attempting to start with those credentials.

I'll look deeper into this when i get in to office tomorrow, but in mean time could you please try the following

  • start MATLAB from your terminal using

matlab -licmode online

And login using the same credentials?

Does MATLAB start?

  • Could you try using the jupyter integration with an older version of MATLAB? Say 24a?

Make sure you update the path to point to 24a after installing it, if you are trying this out.

Finally two more pointers:

  1. MATLAB can now be installed using the MATLAB package manager (mpm)

See https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/MPM.md

  1. One doesn't need to install the MATLAB engine for python to use the jupyter integration as shown in the stack overflow answer.
    You could install it only if you need to use it.

The install steps listed in the main README of this repo should be the only thing you need to do to have this working on any platform.

Thank you for trying the MATLAB integration for Jupyter!

@GlascherLab
Copy link
Author

GlascherLab commented Nov 20, 2024 via email

@krisctl
Copy link
Member

krisctl commented Nov 29, 2024

Dear Jan (@GlascherLab),

The issue which you are seeing seems to be coming from Jupyter not registering MATLAB Kernel from the correct path. We can follow below steps to get it to a working state.

  1. Let's first ensure that homebrew's python is on path. For example, below is the output of running echo $PATH on my terminal.

/opt/homebrew/bin:/opt/homebrew/sbin:/opt/homebrew/opt/[email protected]/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

  1. Since MATLAB Kernel uses python3 command to start the kernel, let's also link python3 to the correct homebrew python by doing:

ln -sf /opt/homebrew/bin/python3.11 /opt/homebrew/bin/python3

We would verify that the above was successful by running which python3 and observing that it returns

/opt/homebrew/bin/python3

  1. Install required packages

/opt/homebrew/bin/python3 -m pip install --no-cache-dir jupyterlab
/opt/homebrew/bin/python3 -m pip install --no-cache-dir jupyter-matlab-proxy

  1. So that Jupyter is able to register MATLAB Kernel, we need to point the Jupyter path to the location where MATLAB Kernel's spec file is present by adding below to the .zshrc or .bash_profile (depending upon shell)

export JUPYTER_PATH="/opt/homebrew/share/jupyter"

  1. For MATLAB Kernel to work correctly, we also need to enable a server extension by running:

/opt/homebrew/bin/jupyter server extension enable --py jupyter_server_proxy --sys-prefix

  1. Finally we start Jupyterlab with the correct app-dir set:

/opt/homebrew/bin/jupyter-lab --app-dir=/opt/homebrew/share/jupyter/lab

This hopefully gets you to a place where you are able to see MATLAB Kernel as well as Open MATLAB tiles in the Jupyterlab launcher interface. Please let me know if this doesn't solve the issue with the system-wide Python and other packages.

Regards,
Krishan

@krisctl krisctl added question Further information is requested answered Issue has been answered waiting for response labels Nov 29, 2024
@krisctl
Copy link
Member

krisctl commented Dec 6, 2024

Dear Jan (@GlascherLab),

I'll be closing this issue as it is considered resolved from our end. Please feel free to leave a comment in case the above instructions don't fully answer your questions and I'll reopen it. Thanks!

@krisctl krisctl closed this as completed Dec 6, 2024
@GlascherLab
Copy link
Author

GlascherLab commented Dec 6, 2024 via email

@krisctl
Copy link
Member

krisctl commented Dec 9, 2024

Thanks for your reply, Jan!

When running the command to enable the jupyter_server_proxy extension, it seems like the preference is given to the jupyterlab package which was downloaded previously using brew. To troubleshoot, I would suggest we start with removing that package by running this command:

brew remove jupyterlab

followed by re-running the step to enable the jupyter_server_proxy extension (which should now ideally enable the extension from right location - /opt/homebrew/lib/python3.11/site-packages)

/opt/homebrew/bin/jupyter server extension enable --py jupyter_server_proxy --sys-prefix

This should enable jupyter_server_proxy extension in the same location as jupyter_matlab_proxy and help with progressing in the workflow.

If this doesn't resolve your issue, kindly share the output of below command to help diagnose this further.

/opt/homebrew/bin/python3 -m pip list | grep -i "jupyter"

HTH!

@krisctl krisctl reopened this Dec 9, 2024
@GlascherLab
Copy link
Author

GlascherLab commented Dec 9, 2024 via email

@krisctl
Copy link
Member

krisctl commented Dec 9, 2024

Hello Jan,

We need jupyter executable to enable/disable the jupyter_server_proxy extension. It appears to me that jupyter executable present in /opt/homebrew/bin was placed there by the jupyterlab cask and not when you performed jupyterlab package installation using pip.

12:48 $ /opt/homebrew/bin/jupyter server extension enable --py jupyter_server_proxy --sys-prefix
jupyter_server_proxy | error adding extension (enabled: True): The module 'jupyter_server_proxy' could not be found (No module named 'jupyter_server_proxy'). Are you sure the extension is installed?
Traceback (most recent call last):
File "/opt/homebrew/Cellar/jupyterlab/4.3.1/libexec/lib/python3.12/site-packages/jupyter_server/extension/manager.py", line 323, in add_extension
extpkg = ExtensionPackage(name=extension_name, enabled=enabled)

It is perhaps a case of mixed environments here. In these logs that you shared earlier and referenced right above, you can see that jupyter from brew is trying to update a different python environment (3.12) than your homebrew python (3.11), hence causing issues with finding jupyter_server_proxy which is a requirement for jupyter_matlab_proxy package.

I would start with removing the jupyterlab cask and performing

/opt/homebrew/bin/python3 -m pip install --no-cache-dir jupyter-core

This would drop a jupyter executable in /opt/homebrew/bin which won't be linked to the cask and possibly help you with moving forward.

Thanks!

@GlascherLab
Copy link
Author

GlascherLab commented Dec 9, 2024 via email

@krisctl
Copy link
Member

krisctl commented Dec 10, 2024

Dear Jan,

Apologies for not providing complete instructions. A mere install of jupyter-core will simply ignore the install process if site-packages are already present. Let's try first getting into a clean state before performing install step.

  1. Remove existing installs of various jupyter-related packages:

/opt/homebrew/bin/python3 -m pip uninstall -y jupyter-core jupyterlab jupyter-server-proxy jupyter-matlab-proxy

This would delete the above-mentioned packages from system-wide Python environment.

  1. Perform re-install of the required packages:

/opt/homebrew/bin/python3 -m pip install jupyter-core jupyterlab jupyter-server-proxy jupyter-matlab-proxy

At this point, you should have a jupyter executable dropped under /opt/homebrew/bin.

  1. Enable jupyter-server-proxy extension:

/opt/homebrew/bin/jupyter server extension enable --py jupyter_server_proxy --sys-prefix

  1. Finally, try launching jupyter-lab:

/opt/homebrew/bin/jupyter-lab --app-dir=/opt/homebrew/share/jupyter/lab

A virtual environment like miniconda, venv, pyenv makes things easy by isolating Python environments and ensuring that all the packages are installed and launched from same location. With the usage of System Python, the end-user is responsible for ensuring the isolation and that's where these issues seems to be stemming from.

Hope that helps in moving things along!

@prabhakk-mw
Copy link
Member

prabhakk-mw commented Dec 10, 2024

To add to Krishan's answer, if you do want to use homebrew's installation of jupyterlab directly, then you have to make sure that you install jupyter-matlab-proxy into the python environment that is installed by brew install jupyterlab.

In a clean environment, (ie: no other conflicting PATH entries with other jupyter or matlab-proxy-app executables.) one could run the following sequence of commands starting from homebrew installation:

# Download and Install BREW
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

if [[ "$(uname)" == "Darwin" ]]; then
    BREW_BIN_DIR=/opt/homebrew/bin
elif [[ "$(uname)" == "Linux" ]]; then
    BREW_BIN_DIR=/home/linuxbrew/.linuxbrew/bin
fi

# Add BREW to PATH
export PATH=$BREW_BIN_DIR:$PATH

# Install JupyterLab using brew
brew install jupyterlab

# Find the right Python to Use
PYTHON_USED_BY_JUPYTER=$(cat `which jupyter` | head -n 1 | cut -d '!' -f 2)
PATH_TO_PYTHON=$(echo $PYTHON_USED_BY_JUPYTER | xargs dirname)
export PATH=$PATH_TO_PYTHON:$PATH

# Install the MATLAB Integration for Jupyter
$PYTHON_USED_BY_JUPYTER -m pip install jupyter-matlab-proxy

# Start using JupyterLab
jupyter lab --ip 0.0.0.0

@GlascherLab
Copy link
Author

GlascherLab commented Dec 10, 2024 via email

@GlascherLab
Copy link
Author

GlascherLab commented Dec 10, 2024 via email

@prabhakk-mw
Copy link
Member

prabhakk-mw commented Dec 10, 2024

@GlascherLab

You could simply skip the line that installs HOWEBREW.
And try running the rest?

Just make sure that which jupyter does not return any results before running the commands.

Because we want to be sure that jupyter has come from the brew install jupyterlab to be the command.

@GlascherLab
Copy link
Author

GlascherLab commented Dec 10, 2024 via email

@prabhakk-mw
Copy link
Member

@GlascherLab

It might be easier help resolve this over a call, I've sent an invite to the email address on your github profile

@GlascherLab
Copy link
Author

GlascherLab commented Dec 11, 2024 via email

@prabhakk-mw
Copy link
Member

Dear Jan,
I've sent the updated meeting invite for Dec 12, 1pm CET. That time works beautifully for my time zone.

At the end of the day, the choice of python installation and environment configuration is based on your usecase, and both configurations (global or env based) are easily done. It would however require care on your part to know what to expect when you are dealing with each environment. We can discuss more on this in the call tomorrow.

Thank you for using the MATLAB integration for Jupyter!

Sincerely
Prabhakar

@GlascherLab
Copy link
Author

GlascherLab commented Dec 11, 2024 via email

@GlascherLab
Copy link
Author

GlascherLab commented Dec 12, 2024 via email

@krisctl
Copy link
Member

krisctl commented Dec 12, 2024

That's great news, Jan!

Thank you for listing out the steps that worked in your case. Glad we could help. Closing this issue as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered Issue has been answered bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants