Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A string file path was read as bytes in pyreadr.read_r() #94

Closed
gatorxiao opened this issue Jun 23, 2023 · 5 comments
Closed

A string file path was read as bytes in pyreadr.read_r() #94

gatorxiao opened this issue Jun 23, 2023 · 5 comments

Comments

@gatorxiao
Copy link

gatorxiao commented Jun 23, 2023

I was trying to read a Rda file but kept getting the error below:

File "/usr/local/lib/python3.8/site-packages/pyreadr/pyreadr.py", line 65, in read_r

raise PyreadrError("File {0} does not exist!".format(filename_bytes))

pyreadr.custom_errors.PyreadrError: File b'/path/to/file/file.Rda' does not exist!

I am sure that the path I pass to pyreadr.read_r() is a valid string, but it seems that there is always a b in front of the string. I have tried using strip() to avoid any possible spaces but it didn't work.
Any suggestions would be greatly appreciated!

@ofajardo
Copy link
Owner

The string is transformed to bytes to be passed to the C library, that detail is not relevant.
You need the file to be in local disk. Remote files or files on mounted remote disks wont work. Pkease check that.

@ofajardo
Copy link
Owner

Another thing to check: the string must be utf-8 encoded. If it is in another encoding transform it to utf-8. It is described in the docs.

@gatorxiao
Copy link
Author

Hi Otto, thank you for your reply. Unfortunately, I still have the same issue. I run the script within Docker. The script and the Rda file are in the same container, so it is not a remote one. The string is utf-8 encoded by default.

@ofajardo
Copy link
Owner

ofajardo commented Jul 7, 2023

strange, I work in Docker containers and it works without issues. Maybe it is the way your volumes are mounted? if you are working on a mounted volume have you tried moving your file to your home directory?
when you get the error, the path printed in bytes, if you translate them to a string, is it correct?

In any case, unfortunately the opening of the file is happening at the C library level, which only accepts local files (home directory in docker works for me), and nothing can be done to change that.

@ofajardo
Copy link
Owner

ofajardo commented Aug 7, 2023

closed because lack of activity

@ofajardo ofajardo closed this as completed Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants