Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code - Open Terminal in Current Directory

I am trying to run python code inside Vs code, when I click "Run Python File" Option from top right (play icon). It shows "FileNotFoundError: [Errno 2] No such file or directory: 'jpgs'"

Upon using "pwd" command in same terminal, it shows It's in "/Users/arsh" Directory instead of my python project directory. I have to cd to that folder and run the button to make it working.

Is there any way in VS code to run the python file from current folder automatically? So every time I don't need to tell terminal to goto project folder then run "Run python code" command from VS Code.

like image 304
Yellow Jacket Sting Avatar asked Jul 16 '26 00:07

Yellow Jacket Sting


1 Answers

In addition to the answers posted already, consider assigning a keyboard shortcut as follows in your keybindings.json:

{
    "key": "cmd+shift+alt+t",
    "command": "workbench.action.terminal.newWithCwd",
    "args": {
        "cwd": "${fileDirname}"
    }
}

This will open a terminal in the folder containing the active file.

like image 99
BallpointBen Avatar answered Jul 18 '26 20:07

BallpointBen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!