Discussion:
Lookuperror : unknown encoding : utf-8
Leo Kislov
2006-10-30 09:27:07 UTC
Permalink
I installed it again but it makes no difference. It still throws me
error for LookUp Error: unknown encoding : utf-8.
Most likely you're not using the new python, you're still running old
one.

-- Leo
Leo Kislov
2006-10-30 07:42:48 UTC
Permalink
Hi,
I wanted to read a file encoded in utf-8 and and using the following
unknown encoding : utf-8. Also I am working on Python version 2.4.1.
import codecs
fileObj = codecs.open( "data.txt", "r", "utf-8" )
Can anyone please guide me how do I get utf-8 activated in my codecs or
any setting needs to be done for the same before using codecs.
What OS? Where did you get your python distribution? Anyway, I believe
utf-8 codec was in the python.org distribution since the introduction
of unicode (around python 2.0). If you can't use utf-8 codec right out
of the box, something is really wrong with your setup.

-- Leo
Leo Kislov
2006-10-30 08:54:57 UTC
Permalink
The OS is Windows XPthen your installation is seriously broken. where did you get the
installation kit? have you removed stuff from the Lib directory ?
</F>
It was already installed on my PC and I have no clue how it was
installed or any changes has been done.
Then it's a distribution of your PC manufacturer. They could omit some
modules like utf-8 codec.
I am just downloading newer
version from python.org and will install and check it. I think there
should be problem with installation itself.
That's a right idea, I'd also recommend to leave the manufacturer's
python distribution alone. Do not remove it, do not upgrade it. Some
programs provided by the manufacturer can stop working. If the
preinstalled python was installed into c:\python24 directory, choose
some other directory when you install python from python.org.

-- Leo
Sachin Punjabi
2006-10-30 09:15:52 UTC
Permalink
Post by Leo Kislov
The OS is Windows XPthen your installation is seriously broken. where did you get the
installation kit? have you removed stuff from the Lib directory ?
</F>
It was already installed on my PC and I have no clue how it was
installed or any changes has been done.Then it's a distribution of your PC manufacturer. They could omit some
modules like utf-8 codec.
I am just downloading newer
version from python.org and will install and check it. I think there
should be problem with installation itself.That's a right idea, I'd also recommend to leave the manufacturer's
python distribution alone. Do not remove it, do not upgrade it. Some
programs provided by the manufacturer can stop working. If the
preinstalled python was installed into c:\python24 directory, choose
some other directory when you install python from python.org.
-- Leo
I installed it again but it makes no difference. It still throws me
error for LookUp Error: unknown encoding : utf-8.

Sachin

Sachin Punjabi
2006-10-30 08:37:20 UTC
Permalink
The OS is Windows XPthen your installation is seriously broken. where did you get the
installation kit? have you removed stuff from the Lib directory ?
</F>
It was already installed on my PC and I have no clue how it was
installed or any changes has been done. I am just downloading newer
version from python.org and will install and check it. I think there
should be problem with installation itself.

Thanx
Sachin.
Fredrik Lundh
2006-10-30 08:29:10 UTC
Permalink
The OS is Windows XP
then your installation is seriously broken. where did you get the
installation kit? have you removed stuff from the Lib directory ?

</F>
Sachin Punjabi
2006-10-30 08:23:18 UTC
Permalink
Post by Leo Kislov
Hi,
I wanted to read a file encoded in utf-8 and and using the following
unknown encoding : utf-8. Also I am working on Python version 2.4.1.
import codecs
fileObj = codecs.open( "data.txt", "r", "utf-8" )
Can anyone please guide me how do I get utf-8 activated in my codecs or
any setting needs to be done for the same before using codecs.What OS? Where did you get your python distribution? Anyway, I believe
utf-8 codec was in the python.org distribution since the introduction
of unicode (around python 2.0). If you can't use utf-8 codec right out
of the box, something is really wrong with your setup.
-- Leo
The OS is Windows XP and also how do I incorporate python distribution.
Disutils folder exists in the python folder. Anything I need to do
there ?

Sachin.
thebjorn
2006-10-30 07:47:41 UTC
Permalink
I wanted to read a file encoded in utf-8 and and using the following
unknown encoding : utf-8. Also I am working on Python version 2.4.1.
You shouldn't have to do anything to have the utf-8 encoding available.
Check in your lib/encodings directory for a file name utf_8.py and the
code in __init__.py in the same directory should take care of the
mapping. This has been this way since at least Python 2.2 (which is the
oldest version I have on this machine).

If that doesn't give you a clue as to what is going on in your setup,
try

u'foo'.encode('utf-8')

at the prompt and post the complete traceback.
import codecs
fileObj = codecs.open( "data.txt", "r", "utf-8" )
That should work fine, although I prefer to explicitly set the mode to
"rb" (it will be set to binary mode behind your back regardless ;-)

hth,
-- bjorn
Sachin Punjabi
2006-10-30 09:27:22 UTC
Permalink
On Oct 30, 12:47 pm, "thebjorn" <BjornSteinarFjeldPetter... at gmail.com>
Post by thebjorn
I wanted to read a file encoded in utf-8 and and using the following
unknown encoding : utf-8. Also I am working on Python version 2.4.1.You shouldn't have to do anything to have the utf-8 encoding available.
Check in your lib/encodings directory for a file name utf_8.py and the
code in __init__.py in the same directory should take care of the
mapping. This has been this way since at least Python 2.2 (which is the
oldest version I have on this machine).
If that doesn't give you a clue as to what is going on in your setup,
try
u'foo'.encode('utf-8')
at the prompt and post the complete traceback.
import codecs
fileObj = codecs.open( "data.txt", "r", "utf-8" )That should work fine, although I prefer to explicitly set the mode to
"rb" (it will be set to binary mode behind your back regardless ;-)
hth,
-- bjorn
I tried with the code you specified on the command line and it works
very much fine.

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
Post by thebjorn
Post by thebjorn
u'foo'.encode('utf-8')
'foo'
Sachin.
Sachin Punjabi
2006-10-30 09:38:16 UTC
Permalink
Post by Leo Kislov
I installed it again but it makes no difference. It still throws me
error for LookUp Error: unknown encoding : utf-8.Most likely you're not using the new python, you're still running old
one.
-- Leo
I installed the newer version on D drive and it was previously
installed on C drive. Also the command which bjorn asked me to execute
on command line worked very much fine.

Sachin.
Fredrik Lundh
2006-10-30 09:45:38 UTC
Permalink
Post by Sachin Punjabi
I installed the newer version on D drive and it was previously
installed on C drive. Also the command which bjorn asked me to execute
on command line worked very much fine.
what happens if you *type* in the problematic statements at the command
line, e.g.
Post by Sachin Punjabi
import codecs
f = codecs.open( "/python24/README.txt", "r", "utf-8" )
if this still gives you the same exception, what output do you do the
Post by Sachin Punjabi
cd \python24
python -v
...
Post by Sachin Punjabi
import codecs
f = codecs.open( "README.txt", "r", "utf-8" )
</F>
Sachin Punjabi
2006-10-30 10:54:34 UTC
Permalink
Post by Leo Kislov
I installed it again but it makes no difference. It still throws me
error for LookUp Error: unknown encoding : utf-8.Most likely you're not using the new python, you're still running old
one.
-- Leo
Actually, I have placed the exe created from python in seperate folder
other than Python root folder. Is this the cause of the problem but I
had set Path to C:\Python24\ in Environment Variables.

Sachin.
Sachin Punjabi
2006-10-30 07:30:24 UTC
Permalink
Hi,

I wanted to read a file encoded in utf-8 and and using the following
syntax in my source which throws me an error specifying Lookuperror :
unknown encoding : utf-8. Also I am working on Python version 2.4.1.

import codecs
fileObj = codecs.open( "data.txt", "r", "utf-8" )

Can anyone please guide me how do I get utf-8 activated in my codecs or
any setting needs to be done for the same before using codecs.

Regards
Sachin Punjabi.
Loading...