我有一个Python脚本,可以正常使用某些文件
with open("input.txt", "r") as file:
在同一文件夹中有input.txt。问题是,当我使用终端启动时,例如
keddad@keddad-pc:~/bioinformatics-algorithms/1.3/PatternMatcher$ python3 ~/bioinformatics-algorithms/1.3/PatternMatcher/main.py
它运行良好,但是当我尝试使用VS Code Debugger /不使用调试器运行它时,它只是找不到文件:
keddad@keddad-pc:~/bioinformatics-algorithms$ cd /home/keddad/bioinformatics-algorithms ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /usr/bin/python3 /home/keddad/.vscode/extensions/ms-python.python-2019.8.30787/pythonFiles/ptvsd_launcher.py --default --nodebug --client --host localhost --port 46499 /home/keddad/bioinformatics-algorithms/1.3/PatternMatcher/main.py
Traceback (most recent call last):
"some traceback here"
File "/home/keddad/bioinformatics-algorithms/1.3/PatternMatcher/main.py", line 19, in <module>
main()
File "/home/keddad/bioinformatics-algorithms/1.3/PatternMatcher/main.py", line 10, in main
with open("input.txt", "r") as file:
FileNotFoundError: [Errno 2] No such file or directory: 'input.txt'
如何让VS Code以我的密码在相同目录中找到文件的方式启动我的密码?
答案 0 :(得分:2)
在launch config中,将CWD更改为文件夹
{
"version": "0.2.0",
"configurations": [
{
....,
"cwd" : "${workspaceFolder}/${relativeFileDirname}"
}
]
}
答案 1 :(得分:1)
您在vscode中的终端位于以下位置:“〜/ bioinformatics-algorithms”
这是终端执行python代码并搜索文件的地方。您必须将终端位置更改为“〜/ bioinformatics-algorithms / 1.3 / PatternMatcher”。