Unable to Find a Resource in Resource Root Folder Follow
Hi, I'm trying to run a simple python script that is referring a file in a configured resource root but getting the exception in the screenshot. What could the problem be?
Please sign in to leave a comment.
Please make sure the working directory in your run/debug configuration is set to the directory containing the `sample_data`
Thanks Andrey for the amazing response time!
But that is not my working directory, it's just a resource directory, and I'm expecting to be able to add as many of those as I want without affecting the working directory. These should just make it easy for me to see different resources in one space where I can refer to them in a relative path. Isn't this the default behavior?
Then, please specify the file path that you want to load relative to the working directory.
If you're workdir is pythonProject, then the path should be `code/sample_data/train.parquet`
Yes, pythonProject is my working directory
But that unfortunately didn't work
Just something I noticed that could help solving this issue. When I ran the same lines of code in Python Console, it went OK:
I tried to add the following two lines shown in the shell above (although I'm sure there's a cleaner way to do it!):
But that also didn't work. The same error kept showing.
Here is the path to the code directory:
Try setting it as the working directory. Or just specify the absolute path to the file.
And what do I do with the project directory here?
What if I want to add another resource directory besides this one?
A Resource Root is available for that purpose, why would I use it if I'm going to add the absolute path after all.
When using python's `open` function, the path need to be specified relative to your working directory. If you want to open another file that is outside of the working directory, an absolute path must be used.
Marking directory as a resource root is helpful to enable path completion in PyCharm. But it has no effect on the Python runtime, which requires that a file is specified relative to the working directory.