Resolved import error 'cannot import name 'BytesType' from 'diskcache.core'' in '/dlwpt-code/p2ch10_explore_data.ipynb' by updating the import statement in 'util/disk.py' .
This is a legacy issue. By inspecting the commit history of the python-diskcache library, you will find that diskcache.core.BytesType was essentially str (in Python 2) or bytes (in Python 3), which was added and then removed.
And diskcache.core.BytesIO is StringIO.cStringIO/StringIO.StringIO (in Python 2) and io.BytesIO (in Python 3).
+if sys.hexversion < 0x03000000:
+ range = xrange
+ try:
+ from cStringIO import StringIO as BytesIO
+ except ImportError:
+ from StringIO import StringIO as BytesIO
+
+else:
+ import io
+ BytesIO = io.BytesIO
Solution
Since we have known what the BytesType and BytesIO should be, let's edit the /util/disk.py directly:
from diskcache import FanoutCache, Disk
from diskcache.core import MODE_BINARY # delete BytesType and BytesIO declarations
BytesType = bytes # Import them by ourselves
import io
BytesIO = io.BytesIO
Resolved import error 'cannot import name 'BytesType' from 'diskcache.core'' in '/dlwpt-code/p2ch10_explore_data.ipynb' by updating the import statement in 'util/disk.py' .
This is a legacy issue. By inspecting the commit history of the python-diskcache library, you will find that
diskcache.core.BytesType
was essentiallystr
(in Python 2) orbytes
(in Python 3), which was added and then removed.And
diskcache.core.BytesIO
isStringIO.cStringIO
/StringIO.StringIO
(in Python 2) andio.BytesIO
(in Python 3).Solution
Since we have known what the
BytesType
andBytesIO
should be, let's edit the/util/disk.py
directly:And that works for me.
Originally posted by @yaner-here in https://github.com/deep-learning-with-pytorch/dlwpt-code/issues/27#issuecomment-1791794582