Python-shell: using venv as pythonPath not working

Viewed 259

I have been studying python-shell documentation and I'm currently trying this:

testhello.py:

print('Hello from python')

on my server.js (using Node.js and Express):

var {PythonShell} = require('python-shell');

//next is inside a bigger function

socket.on("animal", function(){
      ina.low();
      inb.low();

      var options = {
            mode: 'text',
            pythonPath: '/Users/myname/Desktop/final_project/for_pyshell/myvenv/bin/python3',
            pythonOptions: ['-u'],
            scriptPath: '/Users/myname/Desktop/final_project/for_pyshell',
            args: ['value1', 'value2', 'value3']
          };

      PythonShell.run('testhello.py', options, function (err, results) {
         if (err) throw err;

         console.print('results: %j', results);
      });


    }) // closes socket.on 

So my python script and venv are in a different folder than my node app. I don't get any errors but not results either. Is there a reason why referring to virtual environment as pythonPath does not work here and what should one change? Many thanks for any help!

Addition: if I move my python-shell code outside the socket.on structure, I get error:

errno: 'ENOENT'

Addition 2: I got this working with my local Python instead of venv but I would still be interested in using virtual environment if anyone has tips!

0 Answers
Related