Main Content

Pyenv.

Change default environment ofPython翻译

描述

采用Pyenv.要更改Python的默认版本或执行模式®翻译。These changes are persistent across different MATLAB®会话。

例子

pe = pyenv.返回有关当前(默认)Python环境的详细信息作为aPythonenvironment.object.

例子

pe = pyenv('版'',版本的)更改Microsoft上的默认Python版本®Windows®platforms.

笔记

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

pe= pyenv('Version',可执行文件的)指定Python可执行文件的完整路径。您可以在任何平台上使用此语法或重新包装的CPython实现下载。

例子

pe = pyenv('executionmode',executionmode.的)更改Python解释器的默认执行模式。

pe = pyenv('版'',可执行文件,'executionmode',executionmode.的)更改解释器的默认版本和执行模式。

例子

全部收缩

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

将执行模式设置为外部处理

Pyenv.("ExecutionMode"“外包”的)
ans = pythonenvironment with属性:版本:“2.7”可执行文件:“c:\ python27 \ pythonw.exe”库:“c:\ windows \ system32 \ python27.dll”home:“c:\ python27”状态:notloadded executionmode:外部处理

创建变量。

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,请检查Pythonenvironment.版本财产。

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

输入参数

全部收缩

Python版本号,指定为字符串或字符向量(仅限Windows平台)。该版本必须包含一个段期分隔的主要和次要版本号。有关支持版本的信息,请参阅金宝app配置系统以使用Python

Pyenv.查找Windows注册表中的版本。如果您从中下载Python应用程序www.python.org/downloads.那the installation automatically adds the version to the registry. If you download the application from a different source, you must either add it to the registry or use thePyenv.(executable)语法更改版本。

例子:2.7

数据类型:char|细绳

现有Python可执行文件的名称,指定为字符串或字符向量。此参数必须包含Python可执行文件的名称,它可以包含完整路径。

例子:/ usr / bin / python

数据类型:char|细绳

执行模式指示是否将Python脚本运行与Matlab相同的过程,指定为'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库,该库也需要Matlab所需的第三方库

  • 调试工作流程

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

介绍在R2019B.