Hydrogen: Missing environment variables

Created on 13 Aug 2016  路  11Comments  路  Source: nteract/hydrogen

Sorry if this has been covered before, can't seem to find a solution.

When I examine os.environ from jupyter or ipython3 or python3 I can see all of my shell environment variables.

However when I run the same using Hydrogen (Python 3 kernel) in the latest version of Atom, many variables are missing. Specifically, I'm having problems with some CUDA variables needed for Python libraries. This is true whether I start Atom via the command line or otherwise.

Anything I might be missing? Is there a way to manually pass environment variables to Hydrogen?

Most helpful comment

Thanks so much for your help. After finding 0.12.3 didn't solve my issue I did some digging and discovered that OSX 10.11 is known to remove both LD_LIBRARY_PATH and DYLD_LIBRARY_PATH environment variables while SIP is turned on which is why they disappear from Atom's process.env.

While this is certainly not Hydrogen specific, I thought I'd leave this note here for anyone else stuck on trying to use CUDA libraries with it on OSX.

When I set the variables manually in startKernel() of kernel-manager.coffee like so, things work as expected in a Hydrogen session:

process.env.LD_LIBRARY_PATH = process.env.DYLD_LIBRARY_PATH = '/usr/local/cuda/lib'

I attempted the same fix by using Hydrogen's Kernel Specs setting (spec.env), but haven't had any luck. Any issues obvious here?

{
  "kernelspecs": {
    "python3": {
      "resource_dir": "/usr/local/share/jupyter/kernels/python3",
      "spec": {
        "language": "python",
        "display_name": "Python 3",
        "env": {
          "LD_LIBRARY_PATH": "/usr/local/cuda/lib",
          "DYLD_LIBRARY_PATH": "/usr/local/cuda/lib"
        },
        "argv": [
          "/usr/local/opt/python3/bin/python3.5",
          "-m",
          "ipykernel",
          "-f",
          "{connection_file}"
        ]
      }
    }
  }
}

All 11 comments

This sounds like we're not passing process.env on to the spawned process. Went ahead and made #405 for this.

Thanks for reporting. We just released v0.12.3 to fix this.

Thanks so much for your help. After finding 0.12.3 didn't solve my issue I did some digging and discovered that OSX 10.11 is known to remove both LD_LIBRARY_PATH and DYLD_LIBRARY_PATH environment variables while SIP is turned on which is why they disappear from Atom's process.env.

While this is certainly not Hydrogen specific, I thought I'd leave this note here for anyone else stuck on trying to use CUDA libraries with it on OSX.

When I set the variables manually in startKernel() of kernel-manager.coffee like so, things work as expected in a Hydrogen session:

process.env.LD_LIBRARY_PATH = process.env.DYLD_LIBRARY_PATH = '/usr/local/cuda/lib'

I attempted the same fix by using Hydrogen's Kernel Specs setting (spec.env), but haven't had any luck. Any issues obvious here?

{
  "kernelspecs": {
    "python3": {
      "resource_dir": "/usr/local/share/jupyter/kernels/python3",
      "spec": {
        "language": "python",
        "display_name": "Python 3",
        "env": {
          "LD_LIBRARY_PATH": "/usr/local/cuda/lib",
          "DYLD_LIBRARY_PATH": "/usr/local/cuda/lib"
        },
        "argv": [
          "/usr/local/opt/python3/bin/python3.5",
          "-m",
          "ipykernel",
          "-f",
          "{connection_file}"
        ]
      }
    }
  }
}

Oooooh, I don't think we've been using the env key in the spec there.

Now I know why I couldn't reproduce this issue. I followed this guide to disable SIP.

I attempted the same fix by using Hydrogen's Kernel Specs setting (spec.env), but haven't had any luck. Any issues obvious here?

We just released v0.12.4. This should work now.

Thanks so much for looking into this! Hydrogen works perfectly with CUDA now.

I think I have the very same problem on a fresh Atom+Hydrogen installation on Ubuntu 16.04.

import os 
os.environ.keys['LD_LIBRARY_PATH']

Running this lines from terminal (after starting conda venv) allows me to see everything I automatically add to the path when starting the vEnv.
Doing the same within Atom gives me a key-not-found error ... I don't think I can use the solution discussed above, as it seems MacOS specific ...

The kernelspec isn't mac specific. Run jupyter kernelspec list --json to see the kernelspecs installed

Yes, I know and I have all my 2 vEnv in there, but the only way I get the PATH and LD_LIBRARY_PATH correctly set is if I first start the vEnv, and inside it I run atom --new-instance

Yes, in order for Atom to inherit a shell's environment variables, it has to be started from inside that shell.

Was this page helpful?
0 / 5 - 0 ratings