hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

Restart Kernel does not run startup code

Open gragrou opened this issue 6 years ago • 7 comments

Hello there,

First of all, thanks a lot for Hydrogen, this package is amazing. I encountered an issue which, I think, came with the last Hydrogen update.

Description of the issue The default backend for matplotlib plots used to be Qt5, which is the one that is used by default when I run python through a terminal for example. Yet, since the last update, all plots are displayed inline, despite the fact that I did not modify any setting. I thought I would be able to switch back to Qt5 by writing {"Python": "%matplotlib qt5"} in the Startup Code entry of Hydrogen's settings page. Yet, this seems not to be taken into account and figures keep being plotted inline.

I am still able to force the backend switch by writing IPython command directly in the script (e.g. %matplotlib qt5), but this is not satisfactory since the code I'm working on is shared with people not using IPython.

Steps to Reproduce:

  1. Write a python script to plot any figure
  2. Run it through Hydrogen

Versions: Here is my config :

  • OS Ubuntu 16.04 LTS
  • Using python2.7 installed via Anaconda

Atom --version output:

  • Atom : 1.19.3
  • Electron: 1.6.9
  • Chrome : 56.0.2924.87
  • Node : 7.4.0

Hydrogen at current release (1.20.0).

Logs:

I don't know if there is any link with my problem but here is a Hydrogen error that pops in the console

Hydrogen: Could not enable dev tools Error: Cannot find module 'mobx-react-devtools'
    at Module._resolveFilename (module.js:470:15)
    at Module._resolveFilename (/usr/share/atom/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.get_Module._resolveFilename (/usr/share/atom/resources/app/src/module-cache.js:354:58)
    at Module.require (file:///usr/share/atom/resources/app/static/index.js:40:43)
    at require (/usr/share/atom/resources/app/src/native-compile-cache.js:66:33)
    at renderDevTools (/home/my_user_name/.atom/packages/Hydrogen/lib/utils.js:126:24)
    at /home/my_user_name/.atom/packages/Hydrogen/lib/main.js:87:9
    at /usr/share/atom/resources/app/src/config.js:644:26
    at Function.module.exports.Emitter.simpleDispatch (/usr/share/atom/resources/app/node_modules/event-kit/lib/emitter.js:25:20)
    at Emitter.module.exports.Emitter.emit (/usr/share/atom/resources/app/node_modules/event-kit/lib/emitter.js:141:34)
    at Config.module.exports.Config.emitChangeEvent (/usr/share/atom/resources/app/src/config.js:835:35)
    at Config.module.exports.Config.setRawValue (/usr/share/atom/resources/app/src/config.js:621:25)
    at Config.module.exports.Config.set (/usr/share/atom/resources/app/src/config.js:236:20)
    at SettingsPanel.set (/usr/share/atom/resources/app/node_modules/settings-view/lib/settings-panel.js:229:27)
    at HTMLInputElement.changeHandler (/usr/share/atom/resources/app/node_modules/settings-view/lib/settings-panel.js:174:25)

gragrou avatar Aug 25 '17 10:08 gragrou

{"Python": "%matplotlib qt5"} try instead {"Python 3": "%matplotlib qt5"}

The name of the key should be the display_name for the kernel. If you run jupyter kernelspec list --json | grep display_name in your terminal you should get a list of available options

btw the error is unrelated, but I think we can fix that from happening in a future release :smile:

BenRussert avatar Aug 26 '17 13:08 BenRussert

Hello, Thanks for the answer.

Running jupyter kernelspec list --json | grep display_name yielded the following output "display_name": "Python 2". I then tried to set {"Python 2": "%matplotlib qt5"}, which did not work (the backend used by Python was matplotlib inline despite the settings). I also tried {"Python 3": "%matplotlib qt5"} just in case, which did not work either (still matplotlib inline).

Any clue of what the issue could be ?

Thanks for your help :)

gragrou avatar Aug 30 '17 08:08 gragrou

@gragrou could you see what running the command %history outputs any time after starting a kernel? You should see that initial startup code at the top.

{"Python 3": "%matplotlib qt5"} is working for me. If you are missing that first line in your history output we might get closer to the issue. Note that hydrogen:restart-kernel command will not run your startup code (only full startup).

You may also want to try running

from IPython import sys_info

print(sys_info())

or similar as well to ensure it is the version and installation of python you expect to run.

BenRussert avatar Sep 03 '17 21:09 BenRussert

Hello @BenRussert, Thanks for your help, I appreciate. This is precisely what I did not understand:

Note that hydrogen:restart-kernel command will not run your startup code (only full startup).

My backend was in fact correctly set at first Hydrogen startup. Yet, since the startup code "Python 2": "%matplotlib qt5"} does not get reevaluated when using hydrogen:restart-kernel, it switched back to what appears to be Hydrogen's default backend: %matplotlib inline.

This raises the question of why the startup code that the user writes in the settings is not reevaluated when hydrogen:restart-kernelis used. It seems a bit confusing to me and I do not know then how to force the default backend to be %matplotlib qt5 as I often have to use the command hydrogen:restart-kernel. If you can give me any clue on how to do that, it would raise my opinion on Hydrogen from awesome up to ultimate ;)

gragrou avatar Sep 11 '17 20:09 gragrou

@lgeiger, I assumed it is intentional that the startup code is not run on hydrogen:restart-kernel, right?

BenRussert avatar Sep 12 '17 20:09 BenRussert

@lgeiger, I assumed it is intentional that the startup code is not run on hydrogen:restart-kernel, right?

I don't know if it is intentional or not, but even if it is I'd be happy to change it if makes things more consistent.

lgeiger avatar Sep 12 '17 20:09 lgeiger

Hi, I have been looking for some time how to access the StartupCode, since I am new in Atom. Any help welcome. I am getting the following error but do not know how to go about to solve it.

Your Hydrogen config is broken: startupCode

SyntaxError: Unexpected token P in JSON at position 1

AtomicNess123 avatar Jun 07 '21 12:06 AtomicNess123