Python: Lookuperror: Unknown Encoding: Hex
Solution 1:
I've been experiencing the same problem (with json), the solution is to copy missing 'hex_codec.py' file at your 'encodings' Lib folder:
Make sure you have Python 2.7.X installed (you'll find it useful later).
- Go to your Python 2.7.X installation directory for 'encodings' folder (ex. for Win platform: 'C:\Python27\Lib\encodings')
- Copy 'hex_codec.py' or every single '.py' file to your 'build/bdist.linux-i686/egg/encodings' folder. ...
- PROFIT
Solution 2:
I've encounter this problem too, but it happed on a computer that I didn't have access to.
I've renamed encodings/hex_codec.py (and deleted the .pyc) look like what will make this error happen
ActivePython 2.7.0.2 (ActiveState Software Inc.) based on
Python 2.7 (r27:82500, Aug 232010, 17:18:21) [MSC v.150032 bit (Intel)] on win32
Type"help", "copyright", "credits"or"license"for more information.
>>> import json
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\json\__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "c:\Python27\lib\json\decoder.py", line 24, in <module>
NaN, PosInf, NegInf = _floatconstants()
File "c:\Python27\lib\json\decoder.py", line 18, in _floatconstants
_BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
LookupError: unknown encoding: hex
>>>
check your files, hex_encoding is probably missing. or you might have something weird in your PATH / PYTHON_HOME
can you do printenv before running you code ? and "print sys.path" in the interpreter ?
Solution 3:
I got the same problem trying android-python27 (https://code.google.com/p/android-python27/issues/detail?id=30).
Solved by copying binascii.py version from PyPy, and modifying to try binascii.so and fallback to pure-python if cannot import the binary one.
Get the result here: https://gist.github.com/alanjds/6091309
Solution 4:
Have your changed your Python installation? In 3.x, there seem to be less codecs than in 2.x. Especially, hex
and base64
are missing, AFAIK.
Post a Comment for "Python: Lookuperror: Unknown Encoding: Hex"