- Restart Jupyter Notebook:After installing the package, restart your Jupyter Notebook server to ensure it recognizes the newly installed package.
- Verify Installation:In a Jupyter Notebook cell, try importing the MATLAB engine to verify the installation:pythonCopy codeimport matlab.engineIf there are no errors, the installation was successful.
Installation of MatlabEngine on Python in Jupyter Notebook
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello. I have some problem installing MatlabEngine on Python in Jupyter Notebook. I think I am installing the module to a wrong environment but I cannot find a solution. Any feedback is appreciated. Thanks.
Macbook Pro (16-inch, 2011) Apple M1 Max / macOS Monterey 12.4
MATLAB R2022a Update 4 / Jupyter Notebook 6.4.5 / AnacondaNavigator 2.2.0
- What I did on Jupyter.
import os
os.chdir('/Applications/MATLAB_R2022a.app/extern/engines/python')
!python setup.py install
- What I got.
/Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/setuptools/dist.py:544: UserWarning: The version specified ('R2022a') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.
warnings.warn(
running install
/Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
/Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
/Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: R2022a is an invalid version and will not be supported in a future release
warnings.warn(
/Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: R2021b is an invalid version and will not be supported in a future release
warnings.warn(
running bdist_egg
running egg_info
writing dist/matlabengineforpython.egg-info/PKG-INFO
writing dependency_links to dist/matlabengineforpython.egg-info/dependency_links.txt
writing top-level names to dist/matlabengineforpython.egg-info/top_level.txt
/Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/setuptools/command/egg_info.py:632: SetuptoolsDeprecationWarning: Custom 'build_py' does not implement 'get_data_files_without_manifest'.
Please extend command classes from setuptools instead of distutils.
warnings.warn(
reading manifest file 'dist/matlabengineforpython.egg-info/SOURCES.txt'
writing manifest file 'dist/matlabengineforpython.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.9-x86_64/egg
running install_lib
running build_py
creating build/bdist.macosx-10.9-x86_64/egg
creating build/bdist.macosx-10.9-x86_64/egg/matlab
copying build/lib/matlab/__init__.py -> build/bdist.macosx-10.9-x86_64/egg/matlab
creating build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/fevalfuture.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/matlabengine.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/basefuture.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/__init__.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/matlabfuture.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/_arch.txt -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/futureresult.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/enginehelper.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/engineerror.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
copying build/lib/matlab/engine/enginesession.py -> build/bdist.macosx-10.9-x86_64/egg/matlab/engine
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/__init__.py to __init__.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/fevalfuture.py to fevalfuture.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/matlabengine.py to matlabengine.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/basefuture.py to basefuture.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/__init__.py to __init__.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/matlabfuture.py to matlabfuture.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/futureresult.py to futureresult.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/enginehelper.py to enginehelper.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/engineerror.py to engineerror.cpython-38.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/matlab/engine/enginesession.py to enginesession.cpython-38.pyc
creating build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/PKG-INFO -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/SOURCES.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/dependency_links.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying dist/matlabengineforpython.egg-info/top_level.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
matlab.__pycache__.__init__.cpython-38: module references __file__
matlab.__pycache__.__init__.cpython-38: module references __path__
matlab.engine.__pycache__.__init__.cpython-38: module references __file__
creating 'dist/matlabengineforpython-R2022a-py3.8.egg' and adding 'build/bdist.macosx-10.9-x86_64/egg' to it
removing 'build/bdist.macosx-10.9-x86_64/egg' (and everything under it)
Processing matlabengineforpython-R2022a-py3.8.egg
removing '/Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/matlabengineforpython-R2022a-py3.8.egg' (and everything under it)
creating /Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/matlabengineforpython-R2022a-py3.8.egg
Extracting matlabengineforpython-R2022a-py3.8.egg to /Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages
matlabengineforpython R2022a is already the active version in easy-install.pth
Installed /Users/yasunorihayashi/opt/anaconda3/lib/python3.8/site-packages/matlabengineforpython-R2022a-py3.8.egg
Processing dependencies for matlabengineforpython===R2022a
Finished processing dependencies for matlabengineforpython===R2022a
Even with some warnings, it appears the installation is finished.
However, with
conda list
Jupyter says
# packages in environment at /usr/local/anaconda3:
#
# Name Version Build Channel
(skipped)
markdown 3.4.1 pypi_0 pypi
markupsafe 1.1.1 py39h9ed2024_0
mat4py 0.5.0 pypi_0 pypi
matlab 0.1 pypi_0 pypi
matlab_kernel 0.17.1 py39h6e9494a_0 conda-forge
matplotlib 3.4.3 py39hecd8cb5_0
matplotlib-base 3.4.3 py39h0a11d32_0
matplotlib-inline 0.1.2 pyhd3eb1b0_2
(skipped)
I do not see MatlabEngine. I am concerened that I am not intalling the module to the right environment.
Indeed, when I use
!conda list
Jupyter says
# packages in environment at /Users/yasunorihayashi/opt/anaconda3:
#
# Name Version Build Channel
make 4.3 h22f3db7_1 conda-forge
markdown 3.4.1 pypi_0 pypi
markupsafe 2.1.1 py38hed1de0f_1 conda-forge
matlab_kernel 0.17.1 py38h50d1736_0 conda-forge
matlabengineforpython R2021b pypi_0 pypi
matplotlib 3.5.2 py38h50d1736_1 conda-forge
matplotlib-base 3.5.2 py38h1b6b9d1_1 conda-forge
matplotlib-inline 0.1.3 pyhd8ed1ab_0 conda-forge
I do see matlabengineforpython. I see it when I performed conda list from Terminal.
I also tried to use
python setup.py install
Then Jupyter Notebook gives the following error message.
File "/var/folders/tn/ndq7xwrx71vgqpzjb_rl91gc0000gn/T/ipykernel_59616/1000827859.py", line 1
python setup.py install
^
SyntaxError: invalid syntax
Thank you again for your feedback.
0 comentarios
Respuestas (1)
arushi
el 28 de Ag. de 2024
Editada: arushi
el 28 de Ag. de 2024
Hi Yasunori,
The issue you're experiencing is likely due to installing the matlabengineforpython package in a different Python environment than the one Jupyter Notebook is using. Here's how you can resolve this:
1.Verify the Python Environment in Jupyter Notebook: First, check which Python environment Jupyter Notebook is using. You can do this by running the following command in a new Jupyter cell:pythonCopy codeimport sys
print(sys.executable)
This will show the path to the Python executable that Jupyter is using.
2. Install MATLAB Engine in the Correct Environment:If the paths don't match, you need to install the MATLAB Engine API in the environment that Jupyter is using.
3.Use pip Instead of setup.py (Optional):If you continue to encounter warnings with setup.py, you can try using pip to install the package. First, ensure you are in the correct environment, then run:bashCopy codepip install .This command installs the package in the current directory, which should be the MATLAB engine's Python directory.
Hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!