Hydrogen: Cannot find Python kernel in `python -m venv` environment

Created on 3 Dec 2017  路  6Comments  路  Source: nteract/hydrogen

Description:

Hydrogen does not pick up kernels if installed in a "Python 3 venv"

Steps to Reproduce:

  1. Create old-school virtualenv

    mkdir test/
    cd test/
    virtualenv .
    activate
    pip install jupyter
    atom .
    

    Execute some code in Hydrogen, the Kernel is discovered correctly

  2. Create new Python 3 venv

    mkdir test/
    cd test/
    python -m venv .
    activate
    pip install jupyter
    atom .
    

    Execute some code in Hydrogen, the Kernel is not discovered

Versions:

  • Arch latest
  • Python 3.6.3
  • Jupyter 4.4.0
  • Atom:

    $ atom --version
    Atom    : 1.22.1
    Electron: 1.6.15
    Chrome  : 56.0.2924.87
    Node    : 7.4.0
    
    • apm:

      $ apm --version
      (node:16955) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
      apm 1.18.11
      npm 5.6.0
      node 9.2.0 x64
      atom 1.22.1
      python 2.7.14
      git 2.15.1

  • [email protected]

Logs:

Logs for the oldschool virtualenv:

Download the React DevTools and use an HTTP server (instead of a file: URL) for a better development experience: https://fb.me/react-devtools
/usr/lib/atom/src/config.js:736 'Hydrogen.kernelspec' could not set the default. Attempted default: undefined; Schema: {}
module.exports.Config.setDefaults @ /usr/lib/atom/src/config.js:736
3/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: findCodeBlock: 0
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: KernelManager: startKernel: Python 3
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: ZMQKernel: monitor shellSocket
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: ZMQKernel: monitor controlSocket
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: ZMQKernel: monitor ioSocket
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: ZMQKernel: stdout: NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.

To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.

To read more about this, see https://github.com/ipython/ipython/issues/2049


To connect another client to this kernel, use:
    --existing kernel-5aca8409-2eba-4b52-9758-96b6fb0a6851.json

/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: ZMQKernel: ioSocket connected
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: ZMQKernel: shellSocket connected
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: ZMQKernel: controlSocket connected
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: ZMQKernel: all main sockets connected
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: Kernel.execute: import sys
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: IO message: Message
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: Dropped starting status IO message
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: IO message: Message
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: IO message: Message
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: IO message: Message
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: watchview running:
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: shell message: Message
system-checker.coffee:85 spell-check:de-de Can't load de_DE: Cannot find dictionary for de_DE.

Logs for the new-style venv:

Download the React DevTools and use an HTTP server (instead of a file: URL) for a better development experience: https://fb.me/react-devtools
/usr/lib/atom/src/config.js:736 'Hydrogen.kernelspec' could not set the default. Attempted default: undefined; Schema: {}
module.exports.Config.setDefaults @ /usr/lib/atom/src/config.js:736
/home/username/.atom/packages/Hydrogen/lib/utils.js:190 Hydrogen: findCodeBlock: 0
utils.js [sm]:162 Hydrogen: findCodeBlock: 0
kernels

Most helpful comment

Creating a new kernel with ipython kernel install --user --name "kernel_name" in venv works for me. When hydrogen asks, just select the kernel. PS: I also installed jupyter module in venv but I am not sure is it necessary or not.

All 6 comments

Creating a new kernel with ipython kernel install --user --name "kernel_name" in venv works for me. When hydrogen asks, just select the kernel. PS: I also installed jupyter module in venv but I am not sure is it necessary or not.

Yes, user-installed kernels (which have their own set of issues) are fine, autodetection of kernels present in venv is what is failing.

I think at some point Hydrogen explicitly opted to only use user-installed kernels and not perform any sort of autodetection. To be honest I'm not sure why that decision was made (other than to simplify the code)

Though I do think that if you're a user that's already heavily invested into using hydrogen across a range of venvs, installing named kernels provides advantages over auto-detection.

Edit: sorry, I missed the venv vs virtualenv distinction. I've looked a bit into the difference between them (though personally I mostly use conda rather than any flavor of virtualenv)

Yes I believe those steps fix the issue @jzf2101

I think this issue is related to #1911 as python -m venv also creates symlinks to the python executable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ekoepplin picture ekoepplin  路  4Comments

neurotronix picture neurotronix  路  4Comments

Mike-MU10 picture Mike-MU10  路  4Comments

homocomputeris picture homocomputeris  路  4Comments

DannyDannyDanny picture DannyDannyDanny  路  3Comments