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.terminal.executeInFileDir doesn't work if file is on another drive from working directory

See original GitHub issue

Environment data

  • VS Code version: 1.51.1
  • Extension version (available under the Extensions sidebar): 2020.11.358366026
  • OS and version: Windows 10.0.19042
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda Python 3.6.12 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Relevant/affected Python packages and their versions: NA
  • Relevant/affected Python-related VS Code extensions and their versions: NA
  • Value of the python.languageServer setting: Pylance

Expected behaviour

Expect that if the file directory is on a different drive to the working directory and “python.terminal.executeInFileDir” is set to true, that the terminal will change drive, then change directory, then run python file

Actual behaviour

Terminal opens, changes directory and then runs python file

Steps to reproduce:

  1. Have python.terminal.executeInFileDir = True
  2. Open python file on drive other than working directory
  3. Run python file in terminal

Terminal will open, run the ‘cd FileDir’ command but not change drive, and then run the python file

Related Code

Related code appears to be in terminalCodeExecution.ts

if ((!wkspace || fileDirPath !== wkspace.uri.fsPath) && fileDirPath.length > 0) { await this.getTerminalService(file).sendText(`cd ${fileDirPath.fileToCommandArgument()}`); }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
afikrimcommented, Oct 28, 2021

I’d like to start solving this issue

0reactions
karthiknadigcommented, Dec 1, 2021

I see an issue here, running a file in a different drive works. but then when you run a file in the same dir as the workspace, it does not work. It does not restore the directory.

After step 5 of verification, run a python file from the workspace. it sends a cd but not a drive change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run python interactive in current file's directory in ...
In "User Settings", use the search bar to look for "python.terminal.executeInFileDir" and set (=) its value to "true" instead of "false".
Read more >
Running Python Scripts from the Command Line
Type it now and see that the contents are the same as if you opened the "C:" drive in windows. Another command is...
Read more >
Python in Visual Studio Code – November 2021 Release
We are pleased to announce that the November 2021 release of the Python Extension for Visual Studio Code is now available.
Read more >
Visual Studio Code - Opening Files with Python open()
When running Python files using Run Python File in Terminal, Visual Studio Code runs the Pythn file using an absolute path.
Read more >
Generating a List of Files – Python for AV - GitHub Pages
If you plug in an external drive, it is probably mounted as a folder in ... If you find code in this workshop...
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