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

5 visualizaciones (últimos 30 días)
光男
光男 el 19 de Feb. de 2024
Comentada: 光男 el 23 de Feb. de 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フォルダを指すよう設定しました
よろしくお願いします。

Respuestas (1)

Kojiro Saito
Kojiro Saito el 20 de Feb. de 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 comentario
光男
光男 el 23 de Feb. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB の Python ライブラリ en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!