question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jupyter notebook support not finding the correct cwd

See original GitHub issue

Environment data

  • VS Code version: 1.33.1 (Tried with both anaconda installation and debian package installation)
  • Extension version: 2019.4.11987
  • OS and version: Ubuntu 18.04 LTS
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.3 (Anaconda)
  • Type of virtual environment used: conda

Expected behavior

Find the actual path of my python file (/home/theis/code/N_path_intership/PlottingCode/python)

Actual behavior

Debugger does it correctly after adding "cwd": "${fileDirname}" to launch.json, jupyter support doesn’t.

Steps to reproduce:

  1. Simply run
#%%

import os
print("Hello World!")
print(os.getcwd())

GIF version

Without "cwd": "${fileDirname}"

alt-text

With "cwd": "${fileDirname}"

alt-text

Code of my .json files

launch.json settings.json

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
SwimmingTigercommented, Jan 9, 2020

I have the same issue. ${fileDirname} is the default value of python.dataScience.notebookFileRoot but it is completely useless for the remote jupyter server (even if the remote Jupyter server is actually local).

vscode remote jupyter wrong cwd

I noticed that some Untitled*.ipynb were created in the default working directory of the remote jupyter server. So if VSCode is running code in these new notebook files, the working directory will obviously not be correct.

However, I have to use a remote Jupyter server because I need to load pyspark and I haven’t found out how to set up a jupyter startup command in VSCode.

I actually have to start jupyter with the following command:

PYSPARK_DRIVER_PYTHON=jupyter PYSPARK_DRIVER_PYTHON_OPTS="notebook --no-browser" PYSPARK_PYTHON=python3 pyspark

In the end, I chose to first cd to the directory I wanted and then start the remote Jupyter server. This solves the problem, but is not very convenient.

0reactions
rchiodocommented, Aug 6, 2020

This should be solved when microsoft/vscode-jupyter#827 is fixed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jupyter notebook support not finding the correct cwd #3422
@notuntoward it seems that you're running from the terminal. The terminal defaults to the workspace directory (hence your cwd being two levels above),...
Read more >
How to change working directory in Jupyter Notebook?
From windows start menu open “Anaconda Prompt 1 · Find .jupyter folder file path . In command prompt just type 2 or 3...
Read more >
Jupyter Notebook default working directory
Problem is that when running a Jupyter notebook inside of IDEA / PyCharm, the default working directory is the project root.
Read more >
How To Change The Working Directory In A Jupyter ...
The OS command – 'chdir' i.e. Change Working Directory will help you change the working directory in the Jupyter notebook and now you...
Read more >
[Errno 2] No such file or directory
I've tried creating a shared folder for both the notebook and the CSV but the notebook still can't find the CSV file.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found