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

Support setting PYTHONPATH environment variables (or any environment variable) #114

Open
sam-goodwin opened this issue Dec 14, 2023 · 1 comment

Comments

@sam-goodwin
Copy link

I am loading pythonia from a node host process.

I ran into a problem where I could not import python code written locally in my code. I can import modules from my virtual environment, but not locally written python code.

To solve, I needed to set PYTHONPATH, but there was no way to do this with the current code.

I worked around it by patching the IpcPipeCom.js file to pass through environment variables:

this.proc = cp.spawn(process.env.PYTHON_BIN || 'python3', args, { stdio })

this.proc = cp.spawn(process.env.PYTHON_BIN || 'python3', args, {
  stdio,
  // propagate
  env: process.env
})

Then, i can set any environment variables in my node process and have them influence the child python process.

process.env.PYTHONPATH = rootDir;
@extremeheat
Copy link
Owner

Yeah, environment variables set in Node.js with process.env aren't applied to the actual current OS process, but they are treated as such by the Node.js code that checks process.env. As the process' env vars aren't updated, they don't propagate to created child processes, so you do need to pass in the new env vars like you did here.

Feel free to open a PR to do this.

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

2 participants