从django views.py找不到Matlab脚本 [英] Matlab script not found from django views.py

查看:127
本文介绍了从django views.py找不到Matlab脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户自制的Matlab脚本在与我的views.py页面相同的目录中,但是当它被调用时,我收到错误:未定义函数'getRecs'用于输入参数类型'double '。基本上没有找到脚本。



当我使用同一目录中的一个test.py脚本测试脚本时,一切正常,但是通过我的浏览器和开发服务器通过views.py调用时,出现错误。



tools.py:

  def get_recs(passed_list):
eng = matlab.engine.start_matlab()
recs = eng.getRecs(passed_list )
return recs

test.py:(工作正常并且与views.py和getRecs.m相同的目录)
(使用Pydev的运行方式为:Python运行)

 从工具导入* 

test_ratings = [5,0,3,2,1,5]
conv_rates = matlab.double(initializer = test_ratings)
new_recs = get_recs ( conv_rates)
print_list(new_recs)

views.py: (throws error)

 从工具导入* 
test_ratings = [5,0,3,2,1,5 ]
def new_user(request):
conv_rates = matlab.double(initializer = test_ratings)
new_recs = get_recs(conv_rates)
return render_to_response('new_user.html',{' rating_list':new_recs},context_instance = RequestContext(request))

我使用的是Python 2.7,Django 1.9和Matlab R2015b

解决方案

对于任何有这个问题的人来说,像Selcuk所说的开发服务器定义了自己的目录您需要添加要用于引擎的脚本的路径。我这样做是通过添加

  eng.addpath(r'C:\path\to\my\scripts\\ \\')

初始化和启动引擎。


I have a user-made Matlab script in the same directory as my views.py page, but when it is called I receive the error: Undefined function 'getRecs' for input arguments of type 'double'. Basically the script wasn't found.

When I test the script with a test.py script in the same directory everything works fine, but when called through the views.py via my browser and the development server the error appears.

tools.py:

def get_recs(passed_list):
   eng = matlab.engine.start_matlab()
   recs = eng.getRecs(passed_list)
   return recs

test.py: (works fine and is in same directory as views.py and getRecs.m) (Ran using Pydev's run as: Python run)

from tools import *

test_ratings = [5, 0, 3, 2, 1, 5]
conv_rates = matlab.double(initializer=test_ratings)
new_recs = get_recs(conv_rates)
print_list(new_recs)

views.py: (throws error)

from tool import *
test_ratings = [5, 0, 3, 2, 1, 5]
def new_user(request):
    conv_rates = matlab.double(initializer=test_ratings)
    new_recs = get_recs(conv_rates)
    return render_to_response('new_user.html', { 'ratings_list' :new_recs}, context_instance=RequestContext(request)) 

I'm using Python 2.7, Django 1.9, and Matlab R2015b

解决方案

For anyone having this problem in the future: like Selcuk mentioned the development server defines its own directory so you need to add the path to the scripts you want to use to the engine. I did this by addding

eng.addpath(r'C:\path\to\my\scripts\')

after initializing and starting the engine.

这篇关于从django views.py找不到Matlab脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆