ImportError: cannot import name 'escape' from 'cgi'

14,423

Solution 1

I have updated the supervisor package version into: supervisor==4.1.0

https://pypi.org/project/supervisor/4.1.0/

[Fixed a Python 3.8 compatibility issue caused by the removal of cgi.escape(). Patch by Mattia Procopio.]

problem solved.

Solution 2

cgi.escape() has been removed in python 3.8. Quoting from here,

parse_qs, parse_qsl, and escape are removed from the cgi module. They are deprecated in Python 3.2 or older. They should be imported from the urllib.parse and html modules instead.

Since you are importing a third-party module, try using a lower python version.

Share:
14,423

Related videos on Youtube

Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm getting the error message "ImportError: cannot import name 'escape' from 'cgi'" when I try to use following code in pycharm:

    import nltk 
    parser = nltk.ChartParser(grammar, trace=0)
    
    for tree in parser.parse(sent):
        print(tree)
        tree.pretty_print(unicodelines=True)
    

    What should I do to correct it?

    • Nipun Sampath
      Nipun Sampath over 4 years
      what python version do you use? Is it 3.8?
    • Admin
      Admin over 4 years
      Yes, it is 3.8.
  • Admin
    Admin over 4 years
    Thank you for your answer! But is there any other way that doesn't need a downgrade?
  • Nipun Sampath
    Nipun Sampath over 4 years
    I don't think so. You are getting the error because nltk has implemented cgi.escape in its code. Either you'll have to wait until they make nltk compatible with python 3.8 or do it yourself using nltk source. Also, maybe try opening an issue there?