Lookuperror : unknown encoding : utf-8

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sachin Punjabi

    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.

  • Leo Kislov

    #2
    Re: Lookuperror : unknown encoding : utf-8


    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

    Comment

    • thebjorn

      #3
      Re: Lookuperror : unknown encoding : utf-8

      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

      Comment

      • Sachin Punjabi

        #4
        Re: Lookuperror : unknown encoding : utf-8



        On Oct 30, 12:42 pm, "Leo Kislov" <Leo.Kis...@gma il.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.

        Comment

        • Fredrik Lundh

          #5
          Re: Lookuperror : unknown encoding : utf-8

          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>

          Comment

          • Sachin Punjabi

            #6
            Re: Lookuperror : unknown encoding : utf-8



            On Oct 30, 1:29 pm, Fredrik Lundh <fred...@python ware.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.

            Comment

            • Leo Kislov

              #7
              Re: Lookuperror : unknown encoding : utf-8


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

              Comment

              • Sachin Punjabi

                #8
                Re: Lookuperror : unknown encoding : utf-8



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

                Comment

                • Leo Kislov

                  #9
                  Re: Lookuperror : unknown encoding : utf-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

                  Comment

                  • Sachin Punjabi

                    #10
                    Re: Lookuperror : unknown encoding : utf-8



                    On Oct 30, 12:47 pm, "thebjorn" <BjornSteinarFj eldPetter...@gm ail.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.

                    Comment

                    • Sachin Punjabi

                      #11
                      Re: Lookuperror : unknown encoding : utf-8



                      On Oct 30, 2:27 pm, "Leo Kislov" <Leo.Kis...@gma il.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.

                      Comment

                      • Fredrik Lundh

                        #12
                        Re: Lookuperror : unknown encoding : utf-8

                        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>

                        Comment

                        • Sachin Punjabi

                          #13
                          Re: Lookuperror : unknown encoding : utf-8



                          On Oct 30, 2:27 pm, "Leo Kislov" <Leo.Kis...@gma il.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.

                          Comment

                          Working...