Matlab won't run python

202 visualizaciones (últimos 30 días)
Kamala Clark-Swanson
Kamala Clark-Swanson el 15 de Sept. de 2015
Comentada: Javier Redondo el 3 de Abr. de 2024 a las 9:53
I call my function and get undefined variable "py" or function "py.sys.path" I enter pyversion and it returns version: ' ' I verified in Add Path that my function paths are correctly listed. And Which -all Python.exe returns the correct path. I have installed this many times but Matlab version 2015a simply won't run my function. I have 64 bit Matlab and 64 bit python and Windows 7 64bit.

Respuestas (2)

Robert Snoeberger
Robert Snoeberger el 15 de Sept. de 2015
Editada: Robert Snoeberger el 16 de Sept. de 2015
If pyversion returns '', then MATLAB doesn't know where to find your Python installation. You should call pyversion with the path to the python executable [1]. For example, if the executable is located at C:\Python27\python.exe, then call pyversion as follows:
>> pyversion C:\Python27\python.exe
  8 comentarios
Dumitru MECINEANU
Dumitru MECINEANU el 1 de Mzo. de 2024
Editada: Dumitru MECINEANU el 1 de Mzo. de 2024
I have the same problem...
and yes, I have a 32 bit Python version, but also 32 bit Matlab R2015b and 32 bit Runtime v90 for compiled applications.
some observations and explanations :
  1. when PYTHONHOME is empty, pythonversion give me one of many installed Python's versions. I can specify the Python's version I need using pyversion('path'). It works in Matlab but not yet in Runtime. and that is the problem, so I tried to set PYTHONHOME, as sugested here : "when running MATLAB apps, an alternative way to set the interpreter is to use the PYTHONHOME environment variable".
  2. but if PYTHONHOME is specified, pyversion give me an empty answer. And when I try to set him using pyversion('path') it don't works, always the same error : Path argument does not specify a valid executable. I don't understand...
Javier Redondo
Javier Redondo el 3 de Abr. de 2024 a las 9:53
Hi! I am trying to connect python to matlab using pyenv(Version="executable") and I get the following error:
"Error using pyenv
Cannot find shared library for specified Python version. Python must be built with a shared library, and the library must be on the search path"
I have read that it could be solved by using the --enable-shared option in python but I don't know what steps I should follow to do it correctly. Could someone help me? Thanks!

Iniciar sesión para comentar.


Paul Thomas
Paul Thomas el 13 de Feb. de 2019
I first wanted to test if it works in general on my machine and followed the instructions in this video: https://www.youtube.com/watch?v=3D5ym4DvVwo I then got the error "Undefined variable "py" or "class" ...".
This issue was cased by the fact that I had two versions of python installed. One by default from the MAC and Anaconda, which I installed myself. Matlab automatically identified the default version, but using the terminal it only recognized the newer Anaconda version.
So I used the terminal, entered "which python", which showed the path of the Anaconda version and then changed the connected version in Matlab using "pyversion path" and it worked.
I am using macOS Mojave Version 10.14.3 . There might be another way to get the path info, but I am not really familiar with MAC just forced to use it for work.
  3 comentarios
Atef
Atef el 23 de Feb. de 2020
thanks good.
Sarvagya
Sarvagya el 20 de Jul. de 2022
This worked. Thanks

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by