python - MATLAB 无法调用带有导入的 Python 模块

标签 python matlab

我已按照 this 上的说明进行操作页面让 MATLAB 在 python 模块中调用 python 代码。

# mymod.py

def search(words):
    """Return list of words containing 'son'"""
    newlist = [w for w in words if 'son' in w]
    return newlist

然后在 MATLAB 中运行

N = py.list({'Jones','Johnson','James'})
py.mymod.search(N)

并获得所需的输出。但是,当 python 模块本身有导入时,我无法让事情正常工作。例如,将单行 import numpy as np 添加到 mymod.py 会产生错误

Undefined variable "py" or class "py.mymod.search"

在 MATLAB 中运行相同的代码行。我该如何解决这个问题?

最佳答案

matlab在本书第 110 页上,您可以看到导致您看到此错误的可能原因列表以及如何解决这些问题。

原因:

  1. “未安装 Python”(第 1-70 页)
  2. 第 1-70 页上的“Windows 平台上的 Python 64 位/32 位版本”
  3. 第 1-71 页上的“MATLAB 找不到 Python”
  4. “用户定义的 Python 模块中的错误”第 1-71 页
  5. “Python 模块不在 Python 搜索路径上”第 1-71 页
  6. 第 1-72 页的“模块名称冲突”
  7. “Python 尝试在错误的模块中执行命令”第 1-72 页

我建议您完成此解决方案列表,因为您可以看到导致错误的可能原因有多种,如果没有更多信息,我们很难知 Prop 体是哪一个。

关于python - MATLAB 无法调用带有导入的 Python 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45848273/

相关文章:

matlab - 如何打印多个开放图形,如何简化将数据导入 MATLAB

matlab - 在 Matlab 中收缩张量

matlab - Octave fminsearch : Problems with minimization and options

matlab - 使用 OpenCV 官方 Matlab 绑定(bind) cv.calcHist

python - 如何修改 .htaccess 中的 sys.path 以允许 mod_python 看到 Django?

python - 如何在python中没有附加模块的情况下读取RGB图像(JPG)

python - 使用 lxml 获取内部 DTD

image - 如何根据图像中的模式信息为图像提供分值?

python - Django 测试 : no data in temporary database file

python - emacs python Elpy 自动完成不适用于所有人