Unable to Find a Resource in Resource Root Folder

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?

8 comments
Comment actions Permalink

Please make sure the working directory in your run/debug configuration is set to the directory containing the `sample_data`

0
Comment actions Permalink

Thanks Andrey for the amazing response time!

Please make sure the working directory in your run/debug configuration is set to the directory containing the `sample_data`

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?

0
Comment actions Permalink

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`

0
Comment actions Permalink

Yes, pythonProject is my working directory

But that unfortunately didn't work

0
Comment actions Permalink

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!):

import sys; print(...
sys.path.extend(...

But that also didn't work. The same error kept showing.

Any clues?

0
Comment actions Permalink

Here is the path to the code directory:

Try setting it as the working directory. Or just specify the absolute path to the file.

0
Comment actions Permalink

And what do I do with the project directory here?

C:\Workspaces\pycharm\pythonProject

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.

0
Comment actions Permalink

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.

0

Please sign in to leave a comment.