Main Content

Pyenv

Change default environment ofPython口译员

描述

利用Pyenv更改Python的默认版本或执行模式®口译员。These changes are persistent across different MATLAB®会议。

笔记

键入时MATLAB会自动加载Pythonpy。command。MATLAB加载Python之后,您无法更改解释器。要更改解释器,请重新启动MATLAB,然后致电Pyenv

例子

Pyenv显示有关当前(默认)Python环境的详细信息。

例子

Pyenv(名称,价值指定用于设置Python环境的参数。例如,Pyenv('Version','2.7')更改Microsoft上的默认Python版本®Windows®平台为2.7。

pe = pyenv(___另外,将环境详细信息返回脓星环境目的。将此语法与以前的语法中的任何参数一起使用。

例子

全部收缩

pe = pyenv;pe.version
ans = "2.7"

将执行模式设置为OutofProcess

Pyenv("ExecutionMode",,,,“ OutofProcess”
Ans =具有属性的Pythonenvironment:版本:“ 2.7”可执行文件:“ C:\ Python27 \ Pythonw.exe”库:“ C:\ Windows \ System32 \ Python27.dll” home:c:c:\ Python27 status status:OutofProcess

创建变量。

py.list({'周一',,,,'周二',,,,'Wednesday',,,,'周四',,,,'星期五'});

显示过程。MATLAB显示针对您环境的信息。

Pyenv
ans = PythonEnvironment with properties: Version: "2.7" Executable: "C:\Python27\pythonw.exe" Library: "C:\windows\system32\python27.dll" Home: "C:\Python27" Status: Loaded ExecutionMode: OutOfProcess ProcessID: "8196" ProcessName: "MATLABPyHost"
pe = pyenv;如果pe.status ==“加载”disp(“要更改Python版本,请重新启动MATLAB,然后致电Pyenv('版本','2.7')。')别的Pyenv('版本',,,,'2.7');结尾

要验证系统是否安装了Python,请检查脓星环境版本财产。

pe = pyenv;如果isempty(pe.version)disp“Python不是安装”结尾

输入参数

全部收缩

名称值参数

Specify optional pairs of arguments asname1 = value1,...,namen = valuen, 在哪里姓名是参数名称和Value是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名用引号。

例子:pe = pyenv(版本=“/usr/bin/python”,executionMode =“ OutofProcess”)

Python版本号(仅Windows平台)或可执行文件名称,指定为字符串或字符向量。有关支持版本的信息,请参阅万博1manbetx配置您的系统以使用Python

  • 如果版本指定一个数字,然后必须包含th价值e major and minor version numbers separated by a period. The function looks for the version in the Windows registry. If you download the Python application fromwww.python.org/downloads,,,,then the installation automatically adds the version to the registry. If you download the application from a different source, you must either add the version to the registry or callPyenv使用可执行文件名来更改版本。

  • 如果版本是现有可执行文件的名称,然后该值必须包含文件的名称以及文件的完整或相对路径。您可以在任何平台上使用此语法或重新包装CPYTHON实现下载。

例子:'2.7'

例子:'/usr/bin/python'

数据类型:char|细绳

执行模式指示是否在与MATLAB相同的过程中运行Python脚本,指定为“ iNprocess'or“ OutofProcess”。默认值“ iNprocess'在MATLAB过程中运行脚本。将此模式用于至关重要的用例。

“ OutofProcess”starts a separate process and is used for safe execution of Python scripts and libraries. Select“ OutofProcess”为了:

  • 使用Matlab也需要使用不同版本的第三方库的Python库。

  • 调试工作流程。

When you call a Python function out-of-process, there is overhead associated with the call. This behavior might affect performance.

数据类型:char|细绳

版本历史记录

在R2019b中引入