Currently when I debbuging moves to my_proyect and run
/home/my_user/my_company/my_proyect/my_folder/my_code.py
However, I getting the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'data/my_data.csv'
I trying to change the cwd variable in launch.json inside .vscode as follows:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"ENVIROMENT_EXECUTION": "local",
"LOGGING_LEVEL": "info",
"ENVIROMENT_STAGE": "develop",
"ENVIROMENT_DEBUG": "yes"
},
"cwd": "${workspaceFolder}/my_folder"
}
]
}
The structure of the folders is:
my_proyect/my_folder/data/my_data.csv
my_proyect/my_folder/my_code.py
And inside the code I have the following lines:
import pandas as pd
my_data = pd.read_csv("data/my_data.csv")
I note that works perfect if I add my_folder
to the path as follows:
import pandas as pd
my_data = pd.read_csv("my_folder/data/my_data.csv")
But I can't do that because when I deploy my code in AWS Lambda it works perfect. So, Any idea how to solve this issue?
CodePudding user response:
VS Code takes the open folder as the workspace. I have tested according to your directory structure, and there is no problem.
I open the my_project
folder with VS Code and VS Code uses it as a workspace.
Below is my launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"cwd": "${workspaceFolder}/my_folder",
}
]
}
So, please modify your cwd
configuration according to your workspace.
UPDATE:
Open the folder using File --> Open Folder...
Here is your directory:
/home/my_user/my_company/my_proyect/my_folder/my_code.py
If you have my_company
turned on then "cwd"
is
"cwd": "${workspaceFolder}/my_proyect/my_folder/"
If you have my_user
turned on then "cwd"
is
"cwd": "${workspaceFolder}/my_user/my_proyect/my_folder/"
${workspaceFolder}
is just a variable that represents the path to the folder you are currently opening as a workspace.
Of course you can also use absolute path directly as "cwd"
:
"cwd": "/home/my_user/my_company/my_proyect/my_folder/my_code.py"