Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

NameError: name 'unicode' is not defined #24

Open

Description

@ossplus

just a very simple code : print ("first"), have issue:

Traceback (most recent call last):
File "\AppData\Local\LightTable\plugins\Python\py-src\ltmain.py", line 193, in handleEval
code= compile(ensureUtf(code), ensureUtf(data[2]["name"]), 'eval')
File "
\AppData\Local\LightTable\plugins\Python\py-src\ltmain.py", line 50, in ensureUtf
if type(s) == unicode:
NameError: name 'unicode' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "AppData\Local\LightTable\plugins\Python\py-src\ltmain.py", line 197, in handleEval
code= compile(ensureUtf(code), ensureUtf(data[2]["name"]), 'exec')
File "
\AppData\Local\LightTable\plugins\Python\py-src\ltmain.py", line 50, in ensureUtf
if type(s) == unicode:
NameError: name 'unicode' is not defined

Activity

  1. berendbaas commented on Feb 19, 2015

    @berendbaas

    Same problem here, are you running python 3 by chance? In that case, It seems to be because python 3 doesn't have the unicode type anymore as it's been replaced by/incorperated into the 'str' type. Is development being done on python 3 with this plugin? Would be great if it was.
    e2bed09

  2. ossplus commented on Feb 20, 2015

    @ossplus
    Author

    yes. python3.4

  3. berendbaas commented on Feb 20, 2015

    @berendbaas

    If you want to hotfix it for now, you can simply replace the "unicode" by "str" on line 51 of the /py-src/ltmain.py file in the python plugin directory for Light Table. Don't forget to switch it back if you ever need to use python 2 ;)
    It would be great, if there was functionality for doing this which was backwards compatible, or if you could switch in your settings between python2 and python3 evaluation, that would then select the corresponding plugin to run. I don't know which design would be preferred by the Light Table team however.

  4. ergodicbreak commented on Feb 22, 2015

    @ergodicbreak

    @berendbaas maybe this would be a reasonable compatible fix?

    def ensureUtf(s):
      try:
          if type(s) == unicode:
            return s.encode('utf8', 'ignore')
      except: 
        return str(s)
  5. berendbaas commented on Feb 22, 2015

    @berendbaas

    @ergodicbreak Seems like a good way to go to me.

  6. kenny-evitt commented on Jun 28, 2015

    @kenny-evitt

    @berendbaas @ergodicbreak – care to comment on PR #28?

  7. added a commit that references this issue on Jan 15, 2016
  8. RockyRoad29 commented on Jan 15, 2016

    @RockyRoad29
    Contributor

    Hi,
    I'm completely new to LightTable and I might be wrong but I think I found a better fix that I just submitted

        def ensureUtf(s, encoding='utf8'):
          """Converts input to unicode if necessary.
    
          If `s` is bytes, it will be decoded using the `encoding` parameters.
    
          This function is used for preprocessing /source/ and /filename/ arguments
          to the builtin function `compile`.
          """
          # In Python2, str == bytes.
          # In Python3, bytes remains unchanged, but str means unicode
          # while unicode is not defined anymore
          if type(s) == bytes:
            return s.decode(encoding, 'ignore')
          else:
            return s

    I tested it with python2.7.11 and python3.5.1 on my archlinux platform.

    Then, if accepted it makes sense to rename the function to reflect its actual role,
    which I did in a later commit.

  9. dav009 commented on Feb 5, 2016

    @dav009

    Is this issue moving at all? It seems quite relevant yet quite inactive

  10. keith-hall commented on Feb 5, 2016

    @keith-hall

    @dav009 see #47 (comment) for why no Python fixes are being merged at the moment

  11. kenny-evitt commented on Feb 5, 2016

    @kenny-evitt

    @dav009 We need someone to takeover the Python plugin. As Keith pointed out, we've got potential fixes, but we have no-one to review and merge them. Even if you (or anyone else) doesn't want to take responsibility for the entirety of Python in LT or even just the LT Python plugin, I'm willing to merge PRs if enough commenters agreed on which ones should be merged.

  12. meownoid commented on Sep 7, 2016

    @meownoid

    Still not working in 8.0.1. Is LT dead?

  13. sbauer322 commented on Sep 7, 2016

    @sbauer322
    Contributor

    Sorry to hear this is still a problem, @meownoid.

    LightTable is not dead, but the current python plugin maintainer, @stemd, appears to be inactive or otherwise not available. That said, we are probably in need of someone to actively work on the plugin.

    I am not familiar with Python, but there is an open pull request that may contain a fix #47. If anyone is able to review or test the fix then I am happy to merge it in.

  14. stemd commented on Sep 8, 2016

    @stemd
    Collaborator

    I managed to get Python3 working on my setup, idea was to test that on all platforms (Linux, Mac, Windows) before merging.
    Also there was an idea to detect Python2 and Python3, and to adapt automatically, but ClojureScript is not so straightforward, and not all code is well commented.

  15. sbauer322 commented on Sep 8, 2016

    @sbauer322
    Contributor

    @stemd, would you be able to point out the poorly documented Clojurescript files or code that are relevant to you? Happy to bump them up in the list of things to document soon.

  16. added a commit that references this issue on Apr 11, 2017
  17. Aurora11111 commented on Aug 27, 2018

    @Aurora11111

    in python2.x:
    item = unicode(item, 'utf-8')
    in python3.x:
    item = str(item.encode('utf-8'))

  18. omkarvijay5 commented on Feb 6, 2019

    @omkarvijay5

    @berendbaas maybe this would be a reasonable compatible fix?

    def ensureUtf(s):
      try:
          if type(s) == unicode:
            return s.encode('utf8', 'ignore')
      except: 
        return str(s)

    Python 3 renamed the unicode type to str, the old str type has been replaced by bytes
    renaming unicode occurrences with str worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions