R2023aで、py​.sysやpy.os​(MA​TLABから​pyth​on)を呼​び出す方法

5 views (last 30 days)
光男
光男 on 19 Feb 2024
Commented: 光男 on 23 Feb 2024
Sentiment Analysis: Calling Python from MATLABのサンプルプログラムで
名前 'py.sys.path' を解決できません。のエラーが発生しています。
--- CODE ----------------------------------
% py.os.getcwd
pyenv
pathToSpeech = fileparts(which('mySpeechRecognizer.py'))
% Add folders to python system path.
if count(py.sys.path,pathToSpeech) == 0
insert(py.sys.path,int32(0),pathToSpeech);
end
--- ANS ----------------------------------
Version: "3.10"
Executable: "C:\Users\xh4m_\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe"
Library:
"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\python310.dll"
Home: "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0"
Status: NotLoaded
ExecutionMode: InProcess
pathToSpeech = 'C:\Users\xh4m_\Documents\MATLAB\deeplearning\speech_python\github_repo'
--- 設定 ----------------------------------
`pip install speechrecognition pocketsphinx`はインストールしました。
pythonpathも上記python_homeフォルダを指すよう設定しました
よろしくお願いします。

Answers (1)

Kojiro Saito
Kojiro Saito on 20 Feb 2024
Pythonのパスにosとsysが追加されていないようです。
pyrun('import sys,os')
を実行した後でpy.sys.pathなどを実行してみてください。
ただ、Windows AppsフォルダーにインストールされているのでMicrosoftストアからインストールされたPythonのようです。
「MATLAB では、Microsoft® ストアからインストールした CPython バージョンはサポートしていません。」
上記でpy.sysやpy.osが動くようになってもそれ以降でエラーが出る可能性がありますので、https://www.python.org/downloads/からダウンロードしたPythonを使うほうが確実です。
  1 Comment
光男
光男 on 23 Feb 2024
ありがとうございました、これを機会に3個あったpythonバージョンを消して再インストールしました。
Python.orgから、windows installerでインストールしましたが、管理者権限でインストールしなかったためか
ユーザディレクトリーになってしまいましたが、名前 'py.sys.path' は解決できました。
今度うまくいかなかった場合は管理者権限で実行してみます、ありがとうございました。
PythonEnvironment のプロパティ:
Version: "3.10"
Executable: "C:\Users\xh4m_\AppData\Local\Programs\Python\Python310\python.EXE"
Library: "C:\Users\xh4m_\AppData\Local\Programs\Python\Python310\python310.dll"
Home: "C:\Users\xh4m_\AppData\Local\Programs\Python\Python310"
Status: Loaded

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!