py_addpath(director​y, MATLAB_too)

版本 1.2.0.0 (2.0 KB) 作者: Eric Fields
Modify Python search path from MATLAB
538.0 次下载
更新时间 2017/11/9

查看许可证

编者注: This file was selected as MATLAB Central Pick of the Week

py_addpath works like the MATLAB function addpath, but updates the PYTHONPATH instead of the MATLAB path.
Starting in MATLAB 2014b, Python code can be called directly from MATLAB (assuming you have a Python interpreter and it is known to MATLAB). For example, py.statistics.mean([1, 2, 3]) would call the mean function from the statistics module in the Python standard library and return the mean of the array.

To use a function in a Python module from MATLAB, that module must be on the Python search path. Adding its location to the MATLAB search path won't work.

Modules in the standard library or properly installed third party packages are already on the Python search path. But if you have written your own Python functions, you may want to add their location to the search path in the same way you add the location of MATLAB functions and scripts to the MATLAB search path.

py_addpath adds a directory to the Python search path in the same way that the MATLAB function addpath adds a directory to the MATLAB search path. Like addpath, py_addpath only adds the directory for the currently active session: it does not permanently change the PYTHONPATH.

The optional output of py_addpath is the updated list of directories on the Python search path as a cell array.

引用格式

Eric Fields (2024). py_addpath(directory, MATLAB_too) (https://www.mathworks.com/matlabcentral/fileexchange/62703-py_addpath-directory-matlab_too), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2014b
兼容任何版本
平台兼容性
Windows macOS Linux
致谢

启发作品: zipToolsPy

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.2.0.0

Fixed description formatting
Now adds the full path even when the input is a relative path.

1.1.0.0

Added informative error messages.

1.0.0.0

Fixed typos in description.