How Do I Fix Visual Studio Code Path Error?
so I have this problem in visual code, when I open a file in the same directory of a project, visual code doesn't identify the file unless I give him the whole directory This is th
Solution 1:
cwd:
Specifies the current working directory for the debugger, which is the base folder for any relative paths used in code. If omitted, defaults to ${workspaceFolder} (the folder open in VS Code).
And you can set it to:${fileDirname}
- the current opened file's dirname(official docs)
Solution 2:
Try this way to set working directory manually:
/tmp/1/
/tmp/2/file
import osprint("Current working directory: {0}".format(os.getcwd()))
> Current working directory: /tmp/1open('file', 'r')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> FileNotFoundError: [Errno 2] No such file or directory: 'file'os.chdir('/tmp/2')
open('file', 'r')
> <_io.TextIOWrapper name='file' mode='r' encoding='UTF-8'>
Also you can set directory related to the running python file:
import os
print(os.path.dirname(os.path.abspath(__file__)))
python /tmp/1/file.py
> /tmp/1
The good practice is to set application path somewhere in global configuration file
Post a Comment for "How Do I Fix Visual Studio Code Path Error?"