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

ERROR: a bytes-like object is required, not 'str' (h5py v3.0.0) #3245

Closed
GuidoBartoli opened this issue Nov 2, 2020 · 3 comments · Fixed by #3253
Closed

ERROR: a bytes-like object is required, not 'str' (h5py v3.0.0) #3245

GuidoBartoli opened this issue Nov 2, 2020 · 3 comments · Fixed by #3253
Labels
Milestone

Comments

@GuidoBartoli
Copy link

In the latest months I successfully used silx for many data analysis projects and it worked like a charm.

I'm using it in the standard Python + Virtual Environment scenario, but yesterday I had to reinstall it from scratch and when I opened a previously working HDF5 file I received the following error:

a bytes-like object is required, not 'str'   File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/hdf5/Hdf5TreeModel.py", line 520, in data
    return node.dataDescription(role)
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/hdf5/Hdf5Item.py", line 564, in dataDescription
    kind, _label = self.__getDataDescription()
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/hdf5/Hdf5Item.py", line 558, in __getDataDescription
    self.__description = self.__computeDataDescription()
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/hdf5/Hdf5Item.py", line 527, in __computeDataDescription
    return DescriptionType.VALUE, self._getFormatter().humanReadableValue(self.obj)
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/hdf5/Hdf5Formatter.py", line 110, in humanReadableValue
    text = self.__formatter.toString(numpy_object, dtype=dataset.dtype)
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/data/TextFormatter.py", line 299, in toString
    text = [self.toString(d, dtype) for d in data]
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/data/TextFormatter.py", line 299, in <listcomp>
    text = [self.toString(d, dtype) for d in data]
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/data/TextFormatter.py", line 302, in toString
    text = self.__formatH5pyObject(data, dtype)
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/data/TextFormatter.py", line 270, in __formatH5pyObject
    return self.__formatText(data)
  File "/home/bartoli/.virtualenvs/ml/lib/python3.8/site-packages/silx/gui/data/TextFormatter.py", line 200, in __formatText
    text = "\"%s\"" % text.replace("\\", "\\\\").replace("\"", "\\\"")

After a bit of investigation, I found that requirements.txt of silx install the latest version of h5py that 3 days ago was bumped to v3.0.0 and that is the cause of this error. Forcing the installation of the previous v2.10.0 of h5py solves that.

While waiting for an update of silx compatibility against the latest version of h5py, this problem can be solved by adding the line h5py==2.10.0 in requirements.txt.

Can anybody else reproduce this?

Thanks

@GuidoBartoli
Copy link
Author

GuidoBartoli commented Nov 2, 2020

Sorry for the duplicate issue, I just found out that #3240 could solve this problem.

@t20100 t20100 added this to the 0.14 milestone Nov 4, 2020
@t20100 t20100 added the bug label Nov 4, 2020
@t20100
Copy link
Member

t20100 commented Nov 4, 2020

Thanks for the report!

PR #3240 has been merged, but it's most probably not yet enough to fix all issues related to h5py v3.

@t20100
Copy link
Member

t20100 commented Nov 5, 2020

Here is a quick&dirty fix:

silx/gui/data/TextFormatter.py l198:

    def __formatText(self, text):
        if self.__useQuoteForText:
            if isinstance(text, (bytes, numpy.bytes_)):
                text = text.decode('utf-8')
            text = "\"%s\"" % text.replace("\\", "\\\\").replace("\"", "\\\"")
        return text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants