PTVS
PTVS copied to clipboard
Python interactive window should start in the project root directory, not in Python interpreter location
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:
Original Comments
Feedback Bot on 8/24/2023, 09:59 PM:
(private comment, text removed)
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.