Python Error: ModuleNotFoundError: No module named 'sklearn'

8 ビュー (過去 30 日間)
Zair Ahmedi
Zair Ahmedi 2019 年 5 月 22 日
回答済み: Binaya 2024 年 10 月 20 日
Hi,
I was calling Python from MATLAB but I got the above error.
I have installed sklearn using PyCharm and it ran normally using Python.
What should I do to enable the package on MATLAB?
  2 件のコメント
Eric Delgado
Eric Delgado 2021 年 2 月 22 日
編集済み: Eric Delgado 2021 年 2 月 22 日
Hey @Zair Ahmedi, I am having the same issue... I can import "math module", but not "numpy module", for example. Did you find a solution?! I don't want to reinstall Matlab or Python! :)
Eric Delgado
Eric Delgado 2021 年 2 月 22 日
@Zair Ahmedi, I figure out what happened with my issue... I had two instances of Python installed on my computer. So Matlab was pointing to the raw version of Python (without Numpy and others modules).
So I just configure the right version of Python and it's allright now. :)
pyenv('Version', 'C:\ProgramData\Anaconda3\python.exe')

サインインしてコメントする。

回答 (1 件)

Binaya
Binaya 2024 年 10 月 20 日
Hi Zair
I understand that when you are using "sklearn" package in MATLAB you are getting the above error.
It is possible that the "sklearn" package is not in the Python search path which is being used by MATLAB.
Here are two possible options to resolve this issue:
  1. Initialize python environment in MATLAB using "pyenv" command with the Python version that has "sklearn" package installed.
  2. Include the "sklearn" installation in the Python search path using "py.sys.path" command in MATLAB. Here is an example provided below ("sklearnPath" is the directory where sklearn package is installed):
insert(py.sys.path,int64(0),sklearnPath)
Please refer to the below documentation for more details:
  1. pyenv: https://www.mathworks.com/help/matlab/ref/pyenv.html
  2. py.sys.path: https://www.mathworks.com/help/matlab/matlab_external/undefined-variable-py-or-function-py-command.html?searchHighlight=py.sys.path&s_tid=srchtitle_support_results_1_py.sys.path#:~:text=the%20search%20path.-,Python%20Module%20Not%20on%20Python%20Search%20Path,-If%20command%20is

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by