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.

`python.dataScience.notebookFileRoot` needs an option to launch with CWD = current file path

See original GitHub issue

Environment data

  • VS Code version: 1.31
  • Extension version (available under the Extensions sidebar): 2019.1.0
  • OS and version: Debian Stretch
  • Python version (& distribution if applicable, e.g. Anaconda): 3.5.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Relevant/affected Python packages and their versions: N/A

Expected behaviour

Having a Python script with cell markers #%%, I’d expect that setting python.dataScience.notebookFileRoot = ${fileDirname} makes the interactive session start in the directory the file resides.

Maybe I misunderstand that setting? At least, it is what calculateWorkingDirectory is supposed to do, isn’t it?

Also see this Stack Overflow question

Actual behaviour

The interactive session starts from the workspace directory.

Steps to reproduce:

Having a structure like this

workingDir
|- foo
   |- file.py

and a file.py:

#%%
import os
print(os.getcwd())

the output in the interactive session is the absolute path of the workingDir.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:17
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
juliuscrncommented, Aug 7, 2019

While we don’t currently support that I do think that this could be a reasonable option (currently vscode defaults to the workspace root as cwd, which we copied while Jupyter defaults to the path of the file) so I’m keeping this issue open to look into that.

Yes please. When working interactively, I always want the kernel to start in the directory of the file I’m executing. If it is starting elsewhere it will mess up my imports unless I add file’s directory to PATH manually…

4reactions
Ir1dcommented, Sep 22, 2019

image deleting the contents in this block seems to work for me (inside a workspace folder)

Read more comments on GitHub >

github_iconTop Results From Across the Web

`python.dataScience.notebookFileRoot` needs an option to ...
python.dataScience.notebookFileRoot needs an option to launch with CWD = current file path #3605.
Read more >
Current working directory for jupyter notebook sets to temp ...
I use ${fileDirname} in python.dataScience.notebookFileRoot setting. However it uses temporary folder as ${fileDirname} instead of original file ...
Read more >
[FIXED] Current working directory for jupyter notebook sets to ...
I'm trying to set current working directory (CWD) to edited file location for Jupyter Notebook in VS Code. I use ${fileDirname} in python....
Read more >
Current Working Directory - Programming Python, Second ...
When you run a Python script by typing a shell command line like python dir1\dir2\file.py , the CWD is the directory you were...
Read more >
How to Get the Full Path of the Current File Directory in Python?
Method 1: pathlib.cwd(). To get your current path in Python, use the pathlib module in the python standard library and call cwd() that's ......
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