So I have a quarto document where I am working in python. When I run the following line in positron, it works perfectly:
LeavesRadiance = pl.read_csv("Fieldwork/Leaves/Leaves_radiance.csv")
However, when I attempt to preview or render the qmd, I get the following error:
FileNotFoundError: No such file or directory (os error 2): Fieldwork/Leaves/Leaves_radiance.csv
I can fix the rendering issue by changing the code to:
LeavesRadiance = pl.read_csv(os.path.join(os.getcwd(), "Leaves_radiance.csv"))
But then the code does not run in the positron IDE.
How can fix it so that the rendering and the code running both start from same root folder?
You can configure Quarto execute-dir when you create a Quarto project, i.e. add _quarto.yml to your Positron workspace root and make it read:
project:
execute-dir: project
Working directory for Quarto render and preview now matches workspace location, same that's used by interactive session. And you can still render individual files, not just the whole project.
To use paths relative to qmd file location in interactive session, you can change active directory for the active REPL to qmd file location. Either just run os.chdir('path/to/quarto-notebook') in REPL or find "Interpreter: Set as Working Directory in Active Console" from Command Pallete or from context menu in Explorer pane:

Note that you don't have to think too much about path issues if you accept tooling defaults and reorganize your workspace a bit to keep your .qmd files in the workspace root, separated from the data:
.
├── data
│ └── Fieldwork
│ └── Leaves
│ └── Leaves_radiance.csv
└── report.qmd