Foggalong / RobustOCS

Robust optimal contirbution selection problems for genetics with Python
https://pypi.org/project/robustocs
MIT License
1 stars 0 forks source link

loading files #24

Closed sakurita17 closed 1 month ago

sakurita17 commented 1 month ago

Hey @Foggalong ,

I'm encountering an issue while trying to load the .txt files. Despite having imported the necessary module :).

image

Thanks for your help! πŸ™‚ Jaime

Foggalong commented 1 month ago

@sakurita17 Huh, that's weird! If you open the file browser in the same location as test.py what do you see?

sakurita17 commented 1 month ago

@Foggalong Here’s a screenshot of what I see in the file browser. Does this answer the question? right? image

Foggalong commented 1 month ago

Ah yes, I see the issue! When you use VS Code to run test.py from your working directory

~/Documents/GitHub/robust-genetics Copy2/

python runs that script in your working directory, not in test.py's location

~/Documents/GitHub/robust-genetics Copy2/examples/50/

which is two levels deeper. Whether working with Python or similar languages like R or MATLAB, when you run code which involves path to files it always looks for them from your working directory, not from the location of the code.

These three test.py scripts you're trying to use are all designed to be ran from their location, i.e. the same folder as the data files. You can see this in the GitHub workflow which checks the build - the runner changes the working directory to the location of test.py each time.

In your case, test.py is looking for EBV50.txt in your working directory (where it's not found), rather than in the same location as test.py (where it actually is). See also example.py - it's designed to be run from the root of the GitHub repository, so includes explicit paths to the locations of the datafiles. If that's still a bit unclear you might find this StackOverflow question helpful, where other people have given alternative explanations to a similar question :slightly_smiling_face:

sakurita17 commented 1 month ago

Ah yes, I see the issue! When you use VS Code to run test.py from your working directory

~/Documents/GitHub/robust-genetics Copy2/

python runs that script in your working directory, not in test.py's location

~/Documents/GitHub/robust-genetics Copy2/examples/50/

which is two levels deeper. Whether working with Python or similar languages like R or MATLAB, when you run code which involves path to files it always looks for them from your working directory, not from the location of the code.

These three test.py scripts you're trying to use are all designed to be ran from their location, i.e. the same folder as the data files. You can see this in the GitHub workflow which checks the build - the runner changes the working directory to the location of test.py each time.

In your case, test.py is looking for EBV50.txt in your working directory (where it's not found), rather than in the same location as test.py (where it actually is). See also example.py - it's designed to be run from the root of the GitHub repository, so includes explicit paths to the locations of the datafiles. If that's still a bit unclear you might find this StackOverflow question helpful, where other people have given alternative explanations to a similar question πŸ™‚

Thanks for the explanation @Foggalong . It seems to be already running. image