python - 如何在 Django 中调用 "MATLAB engine for Python"?

标签 python django matlab matlab-engine

我已经从 MathWork 安装了“Python 的 MATLAB 引擎”。我的 python 版本是 3.4,如果我将自己编写的 m.file 和 .py 文件放在同一个文件夹下,它会很好用。

但是当我想在 Django 中使用该引擎时,一切都出错了。 .m 函数称为“doa.m”。我的项目结构是这样的: Project Structure

我的 views.py 是:

import os
....
from django.shortcuts import render
import matlab.engine
....
def result(request):
    eng = matlab.engine.start_matlab()
    eng.doa(nargout=0)
    return render(request, 'result.html')

我的 urls.py 是:

url( r'result/$', views.result, name='result'),

但是,当我进入 http://127.0.0.1:8000/result/ ,错误是: 未定义函数或变量 'doa'。 回溯是:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/result/

Django Version: 1.9.2
Python Version: 3.4.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'photos',
 'jfu']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "J:\Program Files\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "J:\Program Files\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "I:\Eclipse_Workspace\demo\photos\views.py" in result
  60.     eng.doa(nargout=0)

File "J:\Program Files\Python34\lib\site-packages\matlab\engine\matlabengine.py" in __call__
  84.                                 _stderr).result()

File "J:\Program Files\Python34\lib\site-packages\matlab\engine\futureresult.py" in result
  106.                 self._future,self._nargout, None, out=self._out, err=self._err)

Exception Type: MatlabExecutionError at /result/
Exception Value: Undefined function or variable 'doa'.

谁能给我解释一下?谢谢!

最佳答案

例如,对于 Matlab 2015b,在“主页”选项卡下,单击“设置路径”,然后单击“添加文件夹”并添加 Django 项目所在的文件夹路径。

关于python - 如何在 Django 中调用 "MATLAB engine for Python"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35391579/

相关文章:

Python "classobj"错误

matlab - 为Matlab编译Windows下的Shogun工具箱

c - 如何在引入 mxIsScalar 之前检查变量是标量还是数组?

matlab - 如何在 MATLAB 中隐藏图形的线条,使其不会超出框架

python - 如何在 Python 中找到带有字符串列表的预先存在的变量?

Python-ldap set_option 不适用于优胜美地

python - 如何从django模型中on_delete的SET值访问请求参数

python - requests.post() 的 CSRF 验证失败

javascript - Django jquery 数据表 : Uncaught TypeError: Cannot read property 'length' of undefined

django - 我如何在 APIView 中使用两个序列化程序?