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

Pass flags to rake jupyter:notebook #29

Open
jorge0136 opened this issue Jul 10, 2020 · 5 comments
Open

Pass flags to rake jupyter:notebook #29

jorge0136 opened this issue Jul 10, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@jorge0136
Copy link

jorge0136 commented Jul 10, 2020

I am attempting to add jupyter_on_rails to an existing rails application in a docker container. When I execute rake jupyter:notebook from within my container I get the following error. It appears that it is an instance of this issue and may well be an issue with the way I have my container configured.

Running jupyter via iruby notebook --port 8888 --ip=0.0.0.0 starts the server ok but I am unable to require 'iruby/rails' within a notebook. Do you have any suggestions for how to pipe flags into the rake task or otherwise troubleshoot this issue?

$ rake jupyter:notebook
JUPYTER_DATA_DIR=/app/.ipython bundle exec iruby register --force
rm -rf /app/.ipython/kernels/rails
cp -r /app/.ipython/kernels/ruby /app/.ipython/kernels/rails
Traceback (most recent call last):
  File "/usr/local/bin/jupyter-notebook", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/jupyter_core/application.py", line 270, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/traitlets/config/application.py", line 663, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/usr/local/lib/python3.7/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 1769, in initialize
    self.init_webapp()
  File "/usr/local/lib/python3.7/dist-packages/notebook/notebookapp.py", line 1490, in init_webapp
    self.http_server.listen(port, self.ip)
  File "/usr/local/lib/python3.7/dist-packages/tornado/tcpserver.py", line 151, in listen
    sockets = bind_sockets(port, address=address)
  File "/usr/local/lib/python3.7/dist-packages/tornado/netutil.py", line 174, in bind_sockets
    sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@jorge0136 jorge0136 changed the title rake jupyter:notebook causes Cannot assign requested address error Pass flags to rake jupyter:notebook Jul 10, 2020
@jorge0136
Copy link
Author

jorge0136 commented Jul 10, 2020

The more I look at this error the less it seems to have anything to do with jupyter_on_rails and more likely my container networking config is to blame. Do you have any suggestions on how to handle the use case where one might want to pass flags to the jupyter command?

I haven't ever found a smooth and easy way to pass flags through rake without making each of them explicit.

$ rake jupyter:notebook --port 8888
invalid option: --port

@jorge0136
Copy link
Author

jorge0136 commented Jul 10, 2020

For a local development workaround, I was able to reconstruct the command the rake task is executing.

First I evaluated ENV['IPYTHONDIR'] || Rails.root / '.ipython' in the rails console. I set the JUPYTER_DATA_DIR env to the output of the command. Finally, I added my required flags. In my case that all shook out to be JUPYTER_DATA_DIR=/app/.ipython jupyter notebook --ip=0.0.0.0 --port 8888.

While this feels like progress, I still haven't solved my root issue. I still get an error when attempting to require 'iruby/rails'. Other ruby gems will load but not this one.

@Yuki-Inoue
Copy link
Owner

Do you have any suggestions on how to handle the use case where one might want to pass flags to the jupyter command?

I think if we are to do this, an cli command implementation of this jupyter_on_rails would be needed, such that bundle exec juptyer_on_rails notebook --ip=0.0.0.0 --port 8888 which includes the current functionality of rake jupyter:notebook.

Doing that is simply a matter of development; if anyone can implement it, I'd be happy to merge; if I can spare time, I'll probably implement this feature, but for now I'm a bit occupied.

@Yuki-Inoue Yuki-Inoue added the enhancement New feature or request label Jul 12, 2020
@tim37021
Copy link

tim37021 commented Jun 27, 2021

I came across this project. Thanks for the life saver.

you can use ssh forwarding for this.
If you are using terminal of VSCode remote. It will forward 8888 to you automatically.

@elalemanyo
Copy link

@jorge0136 @Yuki-Inoue
Jupyter notebooks allow you to set various configuration options using jupyter_notebook_config.py.
This file can be located in the Jupyter configuration directory, which is usually ~/.jupyter/.

By setting the options in the jupyter_notebook_config.py file, you do not need to pass flags when starting the Jupyter notebook server from the command line. The options set in the configuration file will be applied every time the Jupyter notebook server is started. This can be particularly useful if you have a set of options that you always want to use, or if you want to make changes to the default behavior of Jupyter notebooks.

For example, you can set the IP and port like this:

# Set the IP address for Jupyter to listen on
c.NotebookApp.ip = '0.0.0.0'

# Set the port for Jupyter to listen on
c.NotebookApp.port = 8888

This is how I use jupyter_on_rails with a rails application running in docker.
I hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants