Calysto / matlab_kernel

Jupyter Kernel for Matlab
Other
469 stars 76 forks source link

How to call functions in .m files? #131

Closed adamxyang closed 4 years ago

adamxyang commented 4 years ago

I tried calling a function in a .m file in the same directory as my notebook (with the Matlab kernel), but it just showed busy (*) but did not actually run when I checked the CPU usage.

blink1073 commented 4 years ago

Hi @adamxinyuyang, does running addPath('.') first fix the issue?

adamxyang commented 4 years ago

Hi @blink1073, I found the it wasn't just function but Matlab is not working in the kernel. I tried disp(...) and nothing showed up. Do I need to install other packages other than this matlab_kernel?

blink1073 commented 4 years ago

What is the output of python -m matlab_kernel.check?

adamxyang commented 4 years ago

It says /usr/bin/python: No module named matlab_kernel. I installed it with pip install matlab_kernel and the matlab kernel showed up correctly in my notebook.

blink1073 commented 4 years ago

It sounds like you have multiple python versions. What does which pip give you?

adamxyang commented 4 years ago

It says /usr/local/bin/pip.

blink1073 commented 4 years ago

Is there a /usr/local/bin/python?

adamxyang commented 4 years ago

No there's no python in this directory, is python not installed correctly? I'm using a remote computer in the lab, not sure how did they install everything.

xy2419@flann800:/usr/local/bin$ ls
__pycache__              epylint               jupyter-bundlerextension  lldb-argdumper                  pip3            repl_swift              swift-build
alembic                  f2py                  jupyter-cling-kernel      lldb-instr                      pip3.6          rst2html.py             swift-build-tool
aomdec                   f2py3                 jupyter-console           lldb-mi                         plasma_store    rst2html4.py            swift-demangle
aomenc                   f2py3.6               jupyter-kernel            lldb-server                     plutil          rst2html5.py            swift-indent
bazel                    ffmpeg                jupyter-kernelspec        lldb-vscode                     pt2to3          rst2latex.py            swift-package
certipy                  ffplay                jupyter-lab               llvm-cov                        ptdump          rst2man.py              swift-run
clang                    ffprobe               jupyter-labextension      llvm-profdata                   ptrepack        rst2odt.py              swift-test
clang++                  freeze_graph          jupyter-labhub            mako-render                     pttree          rst2odt_prepstyles.py   swiftc
clang-7                  futurize              jupyter-migrate           markdown_py                     py.test         rst2pseudoxml.py        symilar
clang-cl                 google-oauthlib-tool  jupyter-nbconvert         netron                          pygmentize      rst2s5.py               tensorboard
clang-cpp                imcat                 jupyter-nbextension       nvtop                           pyjson5         rst2xetex.py            tf_upgrade_v2
clangd                   iptest                jupyter-notebook          opencv_annotation               pylint          rst2xml.py              tflite_convert
configurable-http-proxy  iptest3               jupyter-qtconsole         opencv_createsamples            pyreverse       rstpep2html.py          toco
convert-caffe2-to-onnx   ipython               jupyter-run               opencv_interactive-calibration  pyrsa-decrypt   saved_model_cli         toco_from_protos
convert-onnx-to-caffe2   ipython3              jupyter-serverextension   opencv_traincascade             pyrsa-encrypt   sdk-module-lists        tqdm
cygdb                    isort                 jupyter-troubleshoot      opencv_version                  pyrsa-keygen    setup_vars_opencv4.sh   wheel
cython                   jlpm                  jupyter-trust             opencv_visualisation            pyrsa-priv2pub  swift                   wsdump.py
cythonize                jp.py                 jupyterhub                opencv_waldboost_detector       pyrsa-sign      swift-api-checker.py
easy_install             jsonschema            jupyterhub-singleuser     pasteurize                      pyrsa-verify    swift-api-digester
easy_install-3.6         jupyter               lldb                      pip                             pytest          swift-autolink-extract
blink1073 commented 4 years ago

What is the output of cat $(which pip)?

adamxyang commented 4 years ago

There seems to be a python3 in bin but I couldn't find it using ls above.

xy2419@flann800:/usr/local/bin$ cat $(which pip)
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
xy2419@flann800:/usr/local/bin$ which pip
/usr/local/bin/pip
blink1073 commented 4 years ago

Aha, so what does /usr/bin/python3 -m matlab_kernel.check give you?

adamxyang commented 4 years ago

Oh there's the Matlab kernel:

xy2419@flann800:/usr/local/bin$ /usr/bin/python3 -m matlab_kernel.check
Matlab kernel v0.16.7
Metakernel v0.24.3
Python v3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0]
Python path: /usr/bin/python3

Connecting to Matlab...
Matlab connection established
Matlab Kernel
blink1073 commented 4 years ago

If you run /usr/bin/python3 and then execute this code, does it work? https://www.mathworks.com/help/matlab/matlab_external/use-the-matlab-engine-workspace-in-python.html

adamxyang commented 4 years ago

It couldn't find the matlab command, which is in another directory /home/bkadirve/matlab2019install/bin/matlab. Do I need to export the matlab path to add it as a command?

xy2419@flann800:/usr/bin$ python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matlab.engine
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matlab'
blink1073 commented 4 years ago

I think you're missing this step: https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html

adamxyang commented 4 years ago

Thank you so much! I think that's the problem, and I'll ask for lab's permission to create the build.