“哪个”是matlab中的函数?

2024-05-13 23:59:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在MATLAB的系统命令中使用“whichpython3”,但它不起作用。这里的目标是编写一个脚本,该脚本可以运行特定版本的python,而无需将路径硬编码到脚本中。我希望脚本找到python3,然后按完整路径名调用它

当我在MATLAB中运行以下命令时

>> [stat, result] = system('which python3')

我得到以下输出:

stat =

 1

result =

 0x0 empty char array

但是,我可以在UNIX中运行以下命令并获得良好的结果:

$ which python3
/usr/local/bin/python3

此外,这在MATLAB中工作良好:

>> [stat, result] = system('which python')
stat =

 0

result =

'/usr/bin/python
'

在UNIX中

$ which python
/usr/bin/python

Tags: 命令版本脚本目标whichbinusrunix
1条回答
网友
1楼 · 发布于 2024-05-13 23:59:29

我得到了some help on this one from the "MATLAB Answers" forum。用户Walter Robertson告诉我

MATLAB typically is launched as a graphics program by the operating systems. Such programs do not execute the user's login scripts, so environment variables are not set to user login values: they stay at the system defaults.

system() does not run scripts in a "login" context, so profile variables are not set up either.

The only thing that executes are the scripts that are run every time a shell is initialized.

因此,我的登录脚本没有运行,因此Python 3的路径没有包含在MATLAB系统运行which命令的上下文中,因此我从系统中得到一个空结果

相关问题 更多 >