Closed basnijholt closed 3 months ago
@basnijholt
Thanks for filing this issue and sorry you too are running into this.
FYI - There's no need to create a new issue, If you or others run into the exact same issue, then providing information in the same issue is preferred
I am writing documentation on how to use our JupyterHub with VS Code and now add this following warning:
[!WARNING] Currently, opening a notebook in VS Code with a JupyterHub kernel will result in an incorrectly set working directory (issue). This can cause issues with relative file paths and imports. To avoid this problem, it's recommended to use this at the start of your notebook
import os; os.chdir('/folder/where/notebook/lives')
.
Do you perhaps know a better workaround?
Sorry, but I haven't had a chance to look at this yet, Will look into this today.
Unfortunately I am having the same issue in a similar remote jupyter environment. Some options I have tried that all similarly return the workspace home folder rather than the notebook directory:
%pwd
import IPython
IPython.get_ipython().starting_dir
import os
os.getcwd()
I have also confirmed that the "Notebook File Root" setting is ${fileDirname} and not ${workspaceFolder}
any help with this would be greatly appreciated!
@DonJayamanne, any suggestions of where to look in debugging this?
@basnijholt
I have also confirmed that the "Notebook File Root" setting is ${fileDirname} and not ${workspaceFolder}
This does not work with remote servers.
Looks like the issue you are running into is https://github.com/microsoft/vscode-jupyter/issues/8771
Found that this isn't an issue with VS Code, but thats just how Jupyter Hub works. Closing in favour of https://github.com/microsoft/vscode-jupyter/issues/8771 You can optionally change this in JupyterHub via a configuration setting to change the default directory for JupyterLab. Again, this is the behaviour of Jupyter Lab/Hub.
Environment data
Dup of https://github.com/microsoft/vscode-jupyter-hub/issues/46 but @DonJayamanne asked for the fully filled in issue template here https://github.com/microsoft/vscode-jupyter-hub/issues/46#issuecomment-2004874516.
Expected behaviour
I open a notebook, e.g., at
/home/bas.nijholt/adaptive-scheduler/example.ipynb
and select a new kernel from JupyterHub.I check
import os; os.getcwd()
and it shows/home/bas.nijholt
instead of the folder in which the notebook lives (/home/bas.nijholt/adaptive-scheduler
).Actual behaviour
I expect that
import os; os.getcwd()
would return/home/bas.nijholt/adaptive-scheduler
instead of my home folder.See this:
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
~/
import os; os.getcwd()
Logs
Output for
Jupyter
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toJupyter
)``` Visual Studio Code (1.87.2, ssh-remote, desktop) Jupyter Extension Version: 2024.2.0. Python Extension Version: 2024.2.1. Pylance Extension Version: 2024.3.1. Platform: linux (x64). Multiple Workspace folders opened ~/proj, ~/adaptive-scheduler, ~/.adaptive-scheduler 00:35:44.655 [info] Telemetry level is off 00:35:44.655 [info] Experiments are disabled, only manually opted experiments are active. 00:35:44.655 [info] User belongs to experiment group 'KernelCompletions' 00:35:44.655 [info] User belongs to experiment group 'DoNotWaitForZmqPortsToBeUsed' 00:35:44.784 [info] Start refreshing Kernel Picker (1710808544784) 00:35:44.792 [info] Using Pylance 00:35:46.114 [info] Process Execution: ~/micromamba/envs/proj/bin/python -m pip list 00:35:47.124 [error] Failed to validate Password info D [FetchError]: request to http://localhost:34931/tree? failed, reason: connect ECONNREFUSED 127.0.0.1:34931 at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED'
}
00:35:47.183 [error] Error fetching kernels from http://localhost:34931/ (localhost): FetchError: request to http://localhost:34931/api/kernels?1710808547148 failed, reason: connect ECONNREFUSED 127.0.0.1:34931
at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
00:35:47.185 [error] UniversalRemoteKernelFinder: Failed to get kernels without cache FetchError: request to http://localhost:34931/api/kernels?1710808547148 failed, reason: connect ECONNREFUSED 127.0.0.1:34931
at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
00:35:47.185 [error] Jupyter Lab Helper:getKernelSpecs failure: Error: Poll (@jupyterlab/services:KernelSpecManager#specs) is disposed.
at v.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/@jupyterlab/services.js:11:10935)
at ni.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/@jupyterlab/services.js:11:29299)
at r.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:198:12579)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 0)
at sD.listKernelsFromConnection (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:308:20060)
at ~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:308:17485
00:35:47.655 [info] Starting Kernel connectToLiveRemoteKernel, ce5ca65b-cf52-4e38-9d15-5e7b887212ba for '~/adaptive-scheduler/example.ipynb' (disableUI=true)
00:35:48.236 [info] Started session for kernel connectToLiveRemoteKernel:ce5ca65b-cf52-4e38-9d15-5e7b887212ba
00:35:48.244 [info] Registering Kernel Completion Provider from kernel Python 3 (ipykernel) (example.ipynb) for language python
00:35:48.529 [error] Failed to validate Password info D [FetchError]: request to http://localhost:34931/tree? failed, reason: connect ECONNREFUSED 127.0.0.1:34931
at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED'
}
00:35:48.576 [error] Error fetching kernels from http://localhost:34931/ (localhost): FetchError: request to http://localhost:34931/api/kernels?1710808548531 failed, reason: connect ECONNREFUSED 127.0.0.1:34931
at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
00:35:48.577 [warn] Could not fetch kernels from the remote server, falling back to cache: TypeError: request to http://localhost:34931/api/kernels?1710808548531 failed, reason: connect ECONNREFUSED 127.0.0.1:34931
00:35:48.577 [error] Jupyter Lab Helper:getKernelSpecs failure: Error: Poll (@jupyterlab/services:KernelSpecManager#specs) is disposed.
at v.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/@jupyterlab/services.js:11:10935)
at ni.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/@jupyterlab/services.js:11:29299)
at r.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:198:12579)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 0)
at sD.listKernelsFromConnection (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:308:20060)
at ~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:308:17959
00:35:49.807 [info] End refreshing Kernel Picker (1710808544784)
00:35:56.778 [info] Disposing kernel ce5ca65b-cf52-4e38-9d15-5e7b887212ba for notebook ~/adaptive-scheduler/example.ipynb due to selection of another kernel or closing of the notebook
00:35:56.778 [info] Dispose Kernel '~/adaptive-scheduler/example.ipynb' associated with '~/adaptive-scheduler/example.ipynb'
00:35:58.781 [info] Start refreshing Kernel Picker (1710808558781)
00:35:58.794 [error] Failed to validate Password info D [FetchError]: request to http://localhost:34931/tree? failed, reason: connect ECONNREFUSED 127.0.0.1:34931
at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED'
}
00:35:58.812 [error] Error fetching kernels from http://localhost:34931/ (localhost): FetchError: request to http://localhost:34931/api/kernels?1710808558795 failed, reason: connect ECONNREFUSED 127.0.0.1:34931
at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
00:35:58.813 [warn] Could not fetch kernels from the remote server, falling back to cache: TypeError: request to http://localhost:34931/api/kernels?1710808558795 failed, reason: connect ECONNREFUSED 127.0.0.1:34931
00:35:58.814 [error] Jupyter Lab Helper:getKernelSpecs failure: Error: Poll (@jupyterlab/services:KernelSpecManager#specs) is disposed.
at v.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/@jupyterlab/services.js:11:10935)
at ni.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/@jupyterlab/services.js:11:29299)
at r.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:198:12579)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 0)
at sD.listKernelsFromConnection (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:308:20060)
at ~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:308:17959
00:35:58.850 [info] End refreshing Kernel Picker (1710808558781)
00:36:00.052 [info] Handle Execution of Cells 0 for ~/adaptive-scheduler/example.ipynb
00:36:00.053 [info] Starting Kernel startUsingRemoteKernelSpec, 0f7cf654e8f4259721462c12497ccc916607080c840d3961d51940c03713d45e..python3./opt/micromamba/envs/jupyterhub/python./.-m#ipykernel_launcher for '~/adaptive-scheduler/example.ipynb' (disableUI=false)
00:36:00.096 [info] http://{REMOVED}:9000/user//: Kernel started: dd3a8adb-fa43-4f92-ab9e-db43e09b6889
00:36:00.422 [info] Started session for kernel startUsingRemoteKernelSpec:0f7cf654e8f4259721462c12497ccc916607080c840d3961d51940c03713d45e..python3./opt/micromamba/envs/jupyterhub/python./.-m#ipykernel_launcher
00:36:00.526 [info] Registering Kernel Completion Provider from kernel Python 3 (ipykernel) for language python
00:36:00.527 [info] Start refreshing Kernel Picker (1710808560527)
00:36:00.546 [info] Kernel acknowledged execution of cell 0 @ 1710808560546
00:36:00.553 [error] Failed to validate Password info D [FetchError]: request to http://localhost:34931/tree? failed, reason: connect ECONNREFUSED 127.0.0.1:34931
at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED'
}
00:36:00.559 [info] End cell 0 execution after 0.013s, completed @ 1710808560559, started @ 1710808560546
00:36:00.566 [error] Error fetching kernels from http://localhost:34931/ (localhost): FetchError: request to http://localhost:34931/api/kernels?1710808560554 failed, reason: connect ECONNREFUSED 127.0.0.1:34931
at ClientRequest. (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/node-fetch.js:1:306417)
at ClientRequest.emit (node:events:514:28)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
00:36:00.567 [warn] Could not fetch kernels from the remote server, falling back to cache: TypeError: request to http://localhost:34931/api/kernels?1710808560554 failed, reason: connect ECONNREFUSED 127.0.0.1:34931
00:36:00.567 [error] Jupyter Lab Helper:getKernelSpecs failure: Error: Poll (@jupyterlab/services:KernelSpecManager#specs) is disposed.
at v.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/@jupyterlab/services.js:11:10935)
at ni.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/node_modules/@jupyterlab/services.js:11:29299)
at r.dispose (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:198:12579)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 0)
at sD.listKernelsFromConnection (~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:308:20060)
at ~/.vscode-server/extensions/ms-toolsai.jupyter-2024.2.0-linux-x64/dist/extension.node.js:308:17959
00:36:00.605 [info] End refreshing Kernel Picker (1710808560527)
```
For completeness, the full env that runs our JupyterHub instance.
Generated with
micromamba create -n jupyterhub -y python=3.11 jupyterhub jupyterlab notebook ipywidgets