bir*_*n04 3 python visual-studio-code
我有一个 python 脚本,它可以使用正常的方式处理一些文件
with open("input.txt", "r") as file:
Run Code Online (Sandbox Code Playgroud)
并且在同一个文件夹中有 input.txt。问题是,当我用终端启动它时,比如
keddad@keddad-pc:~/bioinformatics-algorithms/1.3/PatternMatcher$ python3 ~/bioinformatics-algorithms/1.3/PatternMatcher/main.py
Run Code Online (Sandbox Code Playgroud)
它运行良好,但是当我尝试使用 VS Code 调试器/无调试器运行它时,它只是找不到文件:
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'
Run Code Online (Sandbox Code Playgroud)
如何让 VS Code 以它们在同一目录中找到文件的方式启动我的 scipts?
rio*_*oV8 12
在启动配置中,将 CWD 更改为文件夹
{
"version": "0.2.0",
"configurations": [
{
....,
"cwd" : "${workspaceFolder}/${relativeFileDirname}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3277 次 |
最近记录: |