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

Problems connecting VSCode and Jupyter server #6

Closed
dklotz opened this issue Feb 12, 2024 · 5 comments
Closed

Problems connecting VSCode and Jupyter server #6

dklotz opened this issue Feb 12, 2024 · 5 comments

Comments

@dklotz
Copy link

dklotz commented Feb 12, 2024

First of all: thanks for all the effort, this looks like a great starting place for an AI/ML/Python devcontainer setup!

Sorry for using issues as a "support channel" - if that's not something you want to do, feel free to just close the issue!

I wanted to try this (on my M1 Macbook, so all this relates to the newly added arm64 support from #5) and I ran into the problem that when I opened/started the devcontainer, the jupyter server wasn't running (probably related to #1 - although I see that line has already been added to devcontainer.json). After manually starting start-notebook.sh, jupyter runs and I can connect to the web interface without problems. But when I open notebooks/test.ipynb inside of VSCode, it doesn't find any existing Jupyter kernels. I tried both offered options ("Python Environments" and "Existing Jupyter Server"), but haven't been succesfull with either:

  • The first fails and tells me to pip install ipykernel- which should already be there according to the Dockerfile.
  • For the second I tried http://localhost:8888/ and http://localhost:8888/tree (and the same with 127.0.0.1 instead of localhost), but it fails to connect without any error message. I can see the following 404s in the log of start-notebook.sh each time I try to connect the extension to the server, so maybe I just need to use a different URL?
image
@jakoch
Copy link
Owner

jakoch commented Feb 12, 2024

Thank you for reporting the issue.

Certainly, the default behavior should be the ability to run cells out-of-the-box without encountering any additional configuration issues. Currently, the kernel is not automatically listed as execution environment in VSCode anymore.
I'm still in the process of figuring out whether the problem lies with a misconfiguration on my end or if it's an issue with the upstream extension (microsoft/vscode-jupyter).

Workaround
I can only provide a workaround, which describes the steps to register the kernel manually:

  1. change jupyter notebook config
  2. open terminal of devbox and ./start-notebook.sh
    • jupyter should start and log should contain the following lines (with different token):
[I 2024-02-12 19:13:22.602 ServerApp] Jupyter Server 2.12.5 is running at:
[I 2024-02-12 19:13:22.602 ServerApp] http://localhost:8888/tree?token=66db6aa57b8774e04dfe4e910f01ec90ffb308b1835c3668
[I 2024-02-12 19:13:22.602 ServerApp]     http://127.0.0.1:8888/tree?token=66db6aa57b8774e04dfe4e910f01ec90ffb308b1835c3668
[I 2024-02-12 19:13:22.602 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-02-12 19:13:22.604 ServerApp] 
   
   To access the server, open this file in a browser:
       file:///root/.local/share/jupyter/runtime/jpserver-866-open.html
   Or copy and paste one of these URLs:
       http://localhost:8888/tree?token=66db6aa57b8774e04dfe4e910f01ec90ffb308b1835c3668
       http://127.0.0.1:8888/tree?token=66db6aa57b8774e04dfe4e910f01ec90ffb308b1835c3668
  1. in VSCode open notebooks/test.ipynb
  2. then Select Kernel -> Select Another Kernel -> Existing Jupyter Server
    • first input is the URL: add http://127.0.0.1:8888
    • second input is the Password: add your token from the log

Finally, you should get "Python_3 /opt/venv/bin/python" displayed as execution environment and
this enables you to run all cells with the play button.

I leave this issue open, until the situation resolves..

@jakoch
Copy link
Owner

jakoch commented Feb 13, 2024

Referencing upstream issue: microsoft/vscode-jupyter#15163

@leviznull
Copy link

leviznull commented Feb 14, 2024

@dklotz I had the same issue running on amd64 and managed to fix it by adding the following to the devcontainer

"customizations": {
	"vscode": {
		"extensions": [
			// force jupyter to default to our kernel on all notebooks
			"donjayamanne.vscode-default-python-kernel"
		],
		"settings": {
                        // configure our venv to work with vscode automatically
			"python.terminal.activateEnvironment": true,
			"python.defaultInterpreterPath": "$/opt/venv/bin/python3.11"
		}
	}
}

@jakoch In my opinion it would be worthwhile merging this change, unless you see any complications arising from it.

@dklotz
Copy link
Author

dklotz commented Feb 14, 2024

Thanks, the workaround be @leviznull worked for me! I had to fix one typo (there's a $ sign in the defaultInterpreterPath that doesn't belong there), but after that the notebook worked fine in the extension without any additional setup (apart from once having to select the venv as the kernel, so somehow the vscode-default-python-kernel didn't really do its job, but everything still works after that step).

jakoch added a commit that referenced this issue Feb 14, 2024
set ipykernel name and display_name
replaced deprecated c.ServerApp.token with c.IdentityProvider.token in notebook config
updated readme, changelog, notebooks
@jakoch
Copy link
Owner

jakoch commented Feb 14, 2024

nice workaround @leviznull
you can find the new images here:
https://github.com/jakoch/jupyter-devbox/pkgs/container/jupyter-devbox/178943636?tag=sha-509ce88

@jakoch jakoch closed this as completed Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants