Skip to content

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

@sam-goodwin

Description

@sam-goodwin

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions