0

I'm new to both VS Code and Python, so I apologize if this is already possible, but for the life of me I couldn't see how to change this.

I'm using:

  • VS Code (Win) v1.42.0

  • vscode-python v2020.2.62710

Example: I open mypythonscript.py file in a custom directory, say C:\Users\username\Documents\Python\Test. I then open the Python REPL, and it only ever opens the terminal with current working directory set to C:\Users\username, so if I try to import the current file using import mypythonscript, it fails. I'd really like the REPL to open in the directory of the currently open file/project if possible.

I can do this with the terminal itself by setting terminal.integrated.cwd to ${fileDirname}, but this has no effect on the terminal that the python extension opens. I've tried enabling python.terminal.executeInFileDir but this doesn't help.

Is there a way to do this, or do I need to submit an enhancement request? It seems like such a logical thing to want to do, that if it's not possible I'd even go as far as call it a bug.

pcdev
  • 2,852
  • 2
  • 23
  • 39
  • 1
    In VSCode you can open a single _file_ (the UI bar below is purple), or open a _directory_ (bar is blue). Did you open your python file in directory mode? – hylowaker Feb 13 '20 at 01:35
  • Aha! Thanks @hylowaker Yes, you're on the right track, I had a file opened. In directory mode it does indeed work as I would have expected. However I would have expected it to work the same in file mode rather than drop me into my user home, or at least give me the choice. As I said, the `terminal.integrated.cwd` setting works as expected in file mode, but I'm guessing then that there's no way to configure the Start REPL command to do the same – pcdev Feb 13 '20 at 01:56
  • Can't see any other way to do it, but @hylowaker if you add an answer indicating that you need to open the folder to see the behaviour I described, I'll mark it as an answer. Thanks very much! – pcdev Feb 13 '20 at 20:19

0 Answers0