473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Lookuperror : unknown encoding : utf-8

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.

Oct 30 '06 #1
12 36570

Sachin Punjabi wrote:
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.
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

Oct 30 '06 #2
Sachin Punjabi wrote:
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.
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

Oct 30 '06 #3


On Oct 30, 12:42 pm, "Leo Kislov" <Leo.Kis...@gmail.comwrote:
Sachin Punjabi wrote:
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.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.

Oct 30 '06 #4
Sachin Punjabi wrote:
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>

Oct 30 '06 #5


On Oct 30, 1:29 pm, Fredrik Lundh <fred...@pythonware.comwrote:
Sachin Punjabi wrote:
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.

Oct 30 '06 #6

Sachin Punjabi wrote:
On Oct 30, 1:29 pm, Fredrik Lundh <fred...@pythonware.comwrote:
Sachin Punjabi wrote:
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

Oct 30 '06 #7


On Oct 30, 1:54 pm, "Leo Kislov" <Leo.Kis...@gmail.comwrote:
Sachin Punjabi wrote:
On Oct 30, 1:29 pm, Fredrik Lundh <fred...@pythonware.comwrote:
Sachin Punjabi wrote:
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

Oct 30 '06 #8

Sachin Punjabi wrote:
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

Oct 30 '06 #9


On Oct 30, 12:47 pm, "thebjorn" <BjornSteinarFjeldPetter...@gmail.com>
wrote:
Sachin Punjabi wrote:
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.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.
>>u'foo'.encode('utf-8')
'foo'
>>>
Sachin.

Oct 30 '06 #10


On Oct 30, 2:27 pm, "Leo Kislov" <Leo.Kis...@gmail.comwrote:
Sachin Punjabi wrote:
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.

Oct 30 '06 #11
Sachin Punjabi wrote:
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.
>>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
same in a Python interpreter run with the "-v" option:
d:
cd \python24
python -v
....
>>import codecs
f = codecs.open( "README.txt", "r", "utf-8" )
</F>

Oct 30 '06 #12


On Oct 30, 2:27 pm, "Leo Kislov" <Leo.Kis...@gmail.comwrote:
Sachin Punjabi wrote:
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.

Oct 30 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Philipp Lenssen | last post by:
I want to try the new Yahoo API, but I get the PHP5 error message Unknown encoding "utf-8" in the marked line below... (After that, applying the Xpath will fail as symptom of the first bug.) ...
4
by: Ray B. X. Zhou | last post by:
I use xml.sax to parse big5 encoding xml file. And I got message "unknown encoding: big5". What can I do? Thank you very much. Ray
0
by: Antony | last post by:
Hi! i've a problem with py2exe; my prog. on xp gives to me an error of MIMEText.pyc message.pyc Encoders.pyc: LookupError: unknown encoding: ascii ...but in the python idle 2.3 all works...
12
by: Manso | last post by:
Hi, Our sites need to support utf-8 so web.config has both request and response encoding set to utf-8. The problem is that Request.Querystring doesn't support this and we've tried to find a...
0
by: sindhuja | last post by:
How to change the default encoding of asp .net webservice to ISO-8859-1? I have tried the following but have ' nt got my work done > I modified the globalization attribute in web.config > I...
0
by: Jeff Groves | last post by:
I'm using FreezePython on a Python program that uses wxPython and subprocess. The result almost works, but it always hits this bug: File "velauncher.py", line 847, in Launch File...
2
by: Mario Ruggier | last post by:
On OS X 10.5.2 : $ python Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13) on darwin Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last):...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.