Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run python interactive in current file's directory in Visual Studio Code?

When executing "Run Selection/Line in Python Terminal" command in VSCode, terminal's current working directory is the workspace root directory. How can we set current directory of terminal to the current file's directory when running the selection/line?

like image 746
ozgur Avatar asked Dec 22 '18 23:12

ozgur


People also ask

How do I run a Python script interactively?

To run a Python script interactively, open up your command line and type python. Then hit Enter. You can then go ahead and write any Python code within the interactive mode. When you press Enter, the output of your code appears right away.

How do I open interactive console in VS Code?

To open the terminal: Use the Ctrl+` keyboard shortcut with the backtick character. Use the View > Terminal menu command. From the Command Palette (Ctrl+Shift+P), use the View: Toggle Terminal command.

How do I change the interpreter path in Python VS Code?

To do so, open the Command Palette (Ctrl+Shift+P) and enter Preferences: Open User Settings. Then set python.condaPath , which is in the Python extension section of User Settings, with the appropriate path.


1 Answers

In "User Settings", use the search bar to look for "python.terminal.executeInFileDir" and set (=) its value to "true" instead of "false".

like image 78
Laurent Avatar answered Oct 04 '22 15:10

Laurent