0

I'm trying to run Python from MATLAB, but when I try I got the message:

py.list({'Monday','Tuesday','Wednesday','Thursday','Friday'})

Unable to resolve the name py.list.

I also have tried pyenv

pyenv
ans = 

  PythonEnvironment with properties:

          Version: "3.7"
       Executable: "C:\Users\Familia\.conda\envs\matlab\python.exe"
          Library: "C:\Users\Familia\.conda\envs\matlab\python37.dll"
             Home: "C:\Users\Familia\.conda\envs\matlab"
           Status: NotLoaded
    ExecutionMode: InProcess

Could be my problem the Status? NotLoaded? How can I change that for Loaded? Since this path is with Conda, I also tried to change for another Python version I have installed without Anaconda, with this command:

pe = pyenv('Version','C:\Users\Familia\AppData\Local\Microsoft\WindowsApps\python.exe')

Error using pyenv
Path argument does not specify a valid executable.

How can I overcome that?

5
  • @dubbbdan: That's not valid MATLAB syntax. Commented Jul 20, 2020 at 16:32
  • See possible problems and solutions in the MATLAB documentation: mathworks.com/help/matlab/matlab_external/… Commented Jul 20, 2020 at 16:37
  • @CrisLuengo I have tried the suggestions in the link, but still, the same problem, when I use pyenv I got the error: Path argument does not specify a valid executable. Commented Jul 20, 2020 at 18:52
  • Jennifer: In particular, have you verified that your MATLAB program is 64-bit and your Python program is also 64-bit? You likely have a 32-bit version of Python installed at that location (if it is there at all). Commented Jul 20, 2020 at 20:41
  • @CrisLuengo you're right the version of python was 32bit. thank you Commented Jul 21, 2020 at 8:43

4 Answers 4

2

Well, you are seeing that error because the path you specified is not valid.

Open a Command prompt window and type:

where python

this will return a list of locations of Python installations on your machine. On my machine, the command returns:

C:\Users\paolo\AppData\Local\Programs\Python\Python36\python.exe

so we can use this location when calling pyenv in MATLAB:

>> pyenv('Version','C:\Users\paolo\AppData\Local\Programs\Python\Python36\python.exe')

then I can use py.list:

>> py.list({'Monday','Tuesday','Wednesday','Thursday','Friday'})

ans = 

  Python list with no properties.

    ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
Sign up to request clarification or add additional context in comments.

2 Comments

I have tried that, and the error I have when I do what you explained is : Error using pyenv Path argument does not specify a valid executable.
What's the output of where python?
1

It worked for me by using the path from a created conda environment exclusively having python 3.7 for Matlab 2021a. So the steps were:

  1. conda create --name matlabpy python=3.7 #You can give any name to the env

  2. Add the path where this "matlabpy" environment is located by clicking in "Set Path" in Matlab

  3. Run py.list({'Monday','Tuesday','Wednesday','Thursday','Friday'})

Hope it works for you as well

Comments

0

I manage to overcome that uninstalling python and installing again the 64bit, and during the installation, I chose to add python to the path environment and install for all users. That works for me.

Comments

0

For people working on a network where the MATLAB you are using is installed on another users account you need to share your user's folder with the account that MATLAB is installed on.

Steps:

  1. go to C:\Users and right click on the folder with your username
  2. go to the Sharing tab and click Share...
  3. click on the arrow next to Add, and select Find people...
  4. Search for the user that owns the MATLAB you're using and select it from the search results, then OK
  5. Restart MATLAB

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.