VSCode 를 이용하여 python을 실행할 때에 파일 경로를 제대로 인식하지 못하는 문제가 항상 번거롭게 한다.
실행 파일의 위치 경로를 변수에 저장하고 그 뒤에 상대 경로를 붙여서 파일 로딩을 하거나 해왔다.
path = os.path.abspath(__file__)
dir_path = os.path.dirname(path)
하지만, vscode 의 launch.json 파일의 configuration 에 다음을 넣으면 문제 해결된다.
참고 : Debugging configurations for Python apps in Visual Studio Code
Debugging configurations for Python apps in Visual Studio Code
Details on configuring the Visual Studio Code debugger for different Python applications.
code.visualstudio.com
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env":{
"DISPLAY":":0"
},
"cwd": "${fileDirname}" // 추가
}
]
만약에 다른 경로를 넣고 싶다면 환경변수로 정해진 다른 정보를 참고하여 활용하면 된다.
참고 : Settings Reference for Python (visualstudio.com)
Settings Reference for Python
Settings Reference for the Python extension in Visual Studio Code
code.visualstudio.com
VSCode 를 이용하여 python을 실행할 때에 파일 경로를 제대로 인식하지 못하는 문제가 항상 번거롭게 한다.
실행 파일의 위치 경로를 변수에 저장하고 그 뒤에 상대 경로를 붙여서 파일 로딩을 하거나 해왔다.
path = os.path.abspath(__file__)
dir_path = os.path.dirname(path)
하지만, vscode 의 launch.json 파일의 configuration 에 다음을 넣으면 문제 해결된다.
참고 : Debugging configurations for Python apps in Visual Studio Code
Debugging configurations for Python apps in Visual Studio Code
Details on configuring the Visual Studio Code debugger for different Python applications.
code.visualstudio.com
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env":{
"DISPLAY":":0"
},
"cwd": "${fileDirname}" // 추가
}
]
만약에 다른 경로를 넣고 싶다면 환경변수로 정해진 다른 정보를 참고하여 활용하면 된다.
참고 : Settings Reference for Python (visualstudio.com)
Settings Reference for Python
Settings Reference for the Python extension in Visual Studio Code
code.visualstudio.com