Submersible/node-python-bridge

Can't import modules

ZiggerZZ opened this issue · 6 comments

Hi,

Great project! I was wondering if it is still alive?

My issue is that when I define

var python = pythonBridge({
    python: '/anaconda3/bin/python',
    env: {PYTHONPATH: 'valid/pythonpath'}
});

then I can not import common modules, for instance,numpy.

munro commented

The project is still alive. It really shouldn't be doing anything special than if you were running this in your terminal:

echo "import numpy" | PYTHONPATH="valid/pythonpath" /anaconda3/bin/python

It really sounds like something going on with your Python environment, I would recommend importing os and peeking around os.environ and maybe sys.path from inside python-bridge to see what's going on. Sorry I can't provide any more support beyond that!

Oh, only other thing I can think, is you need to do python.ex if you're running statements, like so:

python.ex`import numpy as np`

Best of luck! Feel free to keep me posted, I'll respond if I can.

I fixed the issue!
If I declare var python without PYTHONPATH

var python = pythonBridge({
    python: '/anaconda3/bin/python',
});

it works :)

By the way, I'm new to the web programming and I just knew that's it's not that easy to use require in browsers. I tried browserify for python-bridge but it didn't work, now I'm trying to make it work with requirejs.
Maybe you already have a solution? @munro

munro commented

@ZiggerZZ No it doesn't—that would be crazy. You could build a backend API and use python-bridge, then have your browser app communicate with that backend. Or you'd have use some tools to cross compile Python to the browser, which would be insane, and probably near impossible for most of the Python libraries you'd want to use.