PTVS icon indicating copy to clipboard operation
PTVS copied to clipboard

Python interactive window should start in the project root directory, not in Python interpreter location

Open vsfeedback opened this issue 1 year ago • 1 comments

This issue has been moved from a ticket on Developer Community.


When a Python interactive window starts, the current directory needs to be the project's root directory. It opens in the Python interpreter location, instead: image.png


Original Comments

Feedback Bot on 8/24/2023, 09:59 PM:

(private comment, text removed)

vsfeedback avatar Sep 08 '23 18:09 vsfeedback

I can't agree more!

import os
print('The path:', os.getcwd())
with open('1.txt', 'w') as f: f.write('1')

The result shouldn't be

The path: C:\Program Files\Python311
Traceback (most recent call last):
  File "C:\Users\***\1.py", line 4, in <module>
    with open('1.txt', 'w') as f: f.write('1')
         ^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '1.txt'

I have to write os.chdir(os.path.dirname(sys.argv[0])) to solve this problem. While this is not appropriate.

Other IDE, such as VS Code, Spyder are in the project root directory.

ShiShuyang avatar Nov 14 '23 05:11 ShiShuyang