Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load model from word2vec:PythonShell-ParseError #52

Closed
yuetianluo opened this issue Aug 10, 2016 · 3 comments
Closed

load model from word2vec:PythonShell-ParseError #52

yuetianluo opened this issue Aug 10, 2016 · 3 comments

Comments

@yuetianluo
Copy link

yuetianluo commented Aug 10, 2016

Hi~
I have just run the word2vec model by using genesis module and save the model. And I want to call python in my sails app and load the model I have generated. And I got the following error. I have spending so much time on that but still couldn't figure out what's run.
Thanks ahead for your help!

here is my code:
word2vec.py
import collections
import gensim, logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
model = gensim.models.Word2Vec.load('course_word2vec')

CourseController.js
var PythonShell = require('python-shell');
var courseid=req.param('courseid');
sails.log.debug(coursed);
var options = {
args: [courseid]
};
PythonShell.run('word2vec.py', options, function (err, results) {
if (err) throw err;
console.log('results: %s', results[0]);
});
return res.ok();
and the error is

`/Users/luoyuetian/Desktop/junior/summerproject/course_recommendation_interface/api/controllers/SimilarcourseController.js:41
if (err) throw err;
^
Error: 2016-08-09 20:51:11,742 : INFO : loading Word2Vec object from course_word2vec
2016-08-09 20:51:11,804 : INFO : setting ignored attribute syn0norm to None
2016-08-09 20:51:11,804 : INFO : setting ignored attribute cum_table to None

at PythonShell.parseError (/Users/luoyuetian/Desktop/junior/summerproject/course_recommendation_interface/node_modules/python-shell/index.js:190:17)
at terminateIfNeeded (/Users/luoyuetian/Desktop/junior/summerproject/course_recommendation_interface/node_modules/python-shell/index.js:98:28)
at ChildProcess.<anonymous> (/Users/luoyuetian/Desktop/junior/summerproject/course_recommendation_interface/node_modules/python-shell/index.js:88:9)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12)

`

@extrabacon
Copy link
Owner

It looks like this Python script is writing to stderr for logging, which is not unusual. Some programs prefer tracing to stderr to suppress noise from stdout and keep the output clean. However, python-shell sees that as an error and throws whatever was read from stderr.

I see two options:

  • Refactor your Python script to prevent it from logging, keeping stderr strictly for normal errors
  • Override PythonShell.prototype.parseError to ignore content from stderr, but you will lose detailed error handling such as the Python traceback. PythonShell will still fail if a real error is encountered by reading the exit code.

@yuetianluo
Copy link
Author

Thank you so much. There is no error after I remove the logging

@hkzak
Copy link

hkzak commented Aug 5, 2019

Hi! How to use python shell with sails.js. ? I want to pass an image from my controller.js to a python object and wait for a json output from the .py object ? how is that possible and whats the proper way of doing it ? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants