-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
It runs fine in python3.6, but runs in python3.12 with the following error:
Traceback (most recent call last):
File "/root/local/test/./test.py", line 7, in <module>
det = charamel.Detector()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/charamel/detector.py", line 67, in __init__
self._weights = load_weights(encodings)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/charamel/resources/__init__.py", line 71, in load_weights
weights[encoding] = _unpack(WEIGHT_DIRECTORY / f'{encoding}.gzip', pattern='>e')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/charamel/resources/__init__.py", line 29, in _unpack
with gzip.open(file, 'rb') as data:
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/gzip.py", line 65, in open
binary_file = GzipFile(filename, gz_mode, compresslevel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/gzip.py", line 201, in __init__
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.12/site-packages/charamel/resources/weights/Encoding.ASCII.gzip'
The reason is that the string conversion mechanism of the enum has been adjusted
The proposed modifications are as follows:
diff --git a/resources/__init__.py b/resources/__init__.py
index 336c41c..ff0ba9e 100644
--- a/resources/__init__.py
+++ b/resources/__init__.py
@@ -68,5 +68,5 @@ def load_weights(encodings: Sequence[Encoding]) -> Dict[Encoding, List[float]]:
"""
weights = {}
for encoding in encodings:
- weights[encoding] = _unpack(WEIGHT_DIRECTORY / f'{encoding}.gzip', pattern='>e')
+ weights[encoding] = _unpack(WEIGHT_DIRECTORY / f'{encoding.value}.gzip', pattern='>e')
return weights
I hope the author can incorporate it and update it.
Best wishes
Metadata
Metadata
Assignees
Labels
No labels