Borrar filtros
Borrar filtros

Python virtual environment setup not working when using pyenv-win

10 visualizaciones (últimos 30 días)
Ben
Ben el 7 de Nov. de 2023
Respondida: Bhanu Prakash el 19 de Jul. de 2024 a las 7:25
Using MATLAB 2021a, I am trying to interface with Python code. I used pyenv-win to install Python 3.8.10 on my Windows computer. I then created a virtual environment using the following command in PowerShell:
"C:\Users\me\.pyenv\pyenv-win\shims\python3.8.bat" -m venv "C:\Users\me\Documents\my-matlab-project\pyVenv"
I then set MATLAB to use this virtual environment by running the following in MATLAB:
pyenv("Version",fullfile("C:\Users\me\Documents\my-matlab-project\pyVenv","Scripts","python"),"ExecutionMode","OutOfProcess");
When I pressed the return key, I saw a Python REPL window appear briefly and then disappear. I then tried to run the following:
py.print("Test");
Several Python windows appeared and disappeared rapidly, and after several seconds, I received the error Unable to resolve the name py.print.
When I ran
pyenv()
in MATLAB, I noticed that the Python library path does not appear to be correct. I am not sure if this is the problem:
ans =
PythonEnvironment with properties:
Version: "3.8"
Executable: "C:\Users\zelnickb\OneDrive - Children's Hospital of Philadelphia\Documents\VCS Repositories\Luminesce\py-venv\Scripts\python.EXE"
Library: "C:\Users\zelnickb\.pyenv\pyenv-win\shims\python38"
Home: "C:\Users\zelnickb\OneDrive - Children's Hospital of Philadelphia\Documents\VCS Repositories\Luminesce\py-venv"
Status: NotLoaded
ExecutionMode: OutOfProcess
How can I correct this problem so that I can run Python code from MATLAB in my virtual environment?

Respuestas (1)

Bhanu Prakash
Bhanu Prakash el 19 de Jul. de 2024 a las 7:25
Hi Ben,
This issue might occur when MATLAB does not find the correct path to the Python library. It can be observed in MATLAB R2021a (the release you are using) and earlier releases.
To resolve the issue and use the pyenv-win virtual environment, you can follow the steps mentioned in the following MATLAB answer posted by the MathWorks Support Team:
Hope this helps!

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by