Reputation: 63
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
Upvotes: 1
Views: 219
Reputation: 63
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.
Upvotes: 3
Reputation: 59425
Django development server (or WSGI server) defines a different default directory than the one your user script resides. Try adding the location of your user script to the search path using addpath
option:
eng = matlab.engine.start_matlab("-addpath /var/django/myproject/myapp/")
Upvotes: 1