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 seem to have any effect

See original GitHub issue

Environment data

  • VS Code version: 1.21.0
  • Extension version (available under the Extensions sidebar): 2018.2.1
  • OS and version: Windows 7 Pro
  • Python version: 3.6.2, 64-bit
  • Type of virtual environment used (if applicable): N/A
  • Relevant/affected Python packages and their versions: N/A

Actual behavior

When I issue the command Python: Run Python File in Terminal, it always starts in the open folder, rather than in the file directory, despite the fact that I have "python.terminal.executeInFileDir": true in my user settings.

This has been a problem since forever; this setting has never worked for me on any previous version.

Expected behavior

The terminal starts in the file directory of the Python script I’m executing.

Steps to reproduce:

  1. Open a Python source file.
  2. Use the command palette to issue Python: Run Python File in Terminal.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

I don’t understand those instructions. If I do ViewOutput, there is no Python in the drop-down. However, there is a Python in the terminal. (If this is what you mean, then the template for the bug report should reflect that.)

Suffice it to say that within the Python script, os.getcwd() is the open folder, when I am expecting it to be the same as sys.path[0] instead.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

This is empty, unless I choose Verbose.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
DonJayamannecommented, Mar 13, 2018

@brettcannon @qubitron Here’s a summary of the issue:

  • Open a workspace ‘a’
  • Enable the setting "python.terminal.executeInFileDir"
  • Open a file that does not belong to the above workspace
  • Execute the file using Python: Run Python File in Terminal

Current behavior

  • If file does not belong to the workspace then we’re not setting the current directory

Proposed behavior

  • If file does not belong to the workspace then set the current directory

I’m not sure why, but we currently have tests to avoid this particular situation (possibly a test to retain the behavior inherited from old code).

0reactions
kimadelinecommented, Jul 25, 2019

✅ validated

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 >
Using Python environments in VS Code
By default, any Python interpreter installed runs in its own global environment. ... with the Python: Select Interpreter command doesn't affect terminal ...
Read more >
VS Code Debugger not working for python - Microsoft Q&A
It seems when I do Run->"start Debugging' no command comes to terminal. Any VS Code log file that I can look at to...
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 >
Newbie Help: Terminal Can't Find Python
Newbie help! (Mac OS 11.1) I've downloaded Python 3.9 and PyCharm and have been working through a “Great Courses” video, but I'm stuck....
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