Comments you submit will be routed for moderation. If you have an account, please log in first.
Modify

Ticket #523 (closed defect: fixed)

Opened 15 months ago

Last modified 4 months ago

Can't use CherryPy due to KeyError

Reported by: dn@… Owned by: matysek
Priority: normal Milestone:
Component: PyInstaller Version: 1.5.1
Severity: normal Keywords:
Cc:

Description

CherryPy? uses the following code to be compatible with both Python 3 and Python 2. When I attempt to use this with PyInstaller?, I get a KeyError? rather then an ImportError?, so execution fails:

try:
    # Python 3
    from urllib.parse import urljoin, urlencode
    from urllib.parse import quote, quote_plus
    from urllib.request import unquote, urlopen
    from urllib.request import parse_http_list, parse_keqv_list
except ImportError:
    # Python 2
    from urlparse import urljoin
    from urllib import urlencode, urlopen
    from urllib import quote, quote_plus
    from urllib import unquote
    from urllib2 import parse_http_list, parse_keqv_list
Traceback (most recent call last):
  File "<string>", line 18, in <module>
  File "c:\Source\NS2Update\pyinstaller-1.5.1\iu.py", line 436, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "c:\Source\NS2Update\pyinstaller-1.5.1\iu.py", line 521, in doimport
    exec co in mod.__dict__
  File "c:\Source\NS2Update\build\pyi.win32\console\outPYZ1.pyz/webserver.webserver", line 2, in <module>
  File "c:\Source\NS2Update\pyinstaller-1.5.1\iu.py", line 436, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "c:\Source\NS2Update\pyinstaller-1.5.1\iu.py", line 521, in doimport
    exec co in mod.__dict__
  File "c:\Source\NS2Update\build\pyi.win32\console\outPYZ1.pyz/cherrypy", line62, in <module>
  File "c:\Source\NS2Update\pyinstaller-1.5.1\iu.py", line 436, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "c:\Source\NS2Update\pyinstaller-1.5.1\iu.py", line 521, in doimport
    exec co in mod.__dict__
  File "c:\Source\NS2Update\build\pyi.win32\console\outPYZ1.pyz/cherrypy._cpcompat", line 146, in <module>
  File "c:\Source\NS2Update\pyinstaller-1.5.1\iu.py", line 454, in importHook
    del sys.modules[fqname]
KeyError: 'urllib.parse'

As far as I can tell, a hook really wouldn't help this, as the 'urllib.parse' module doesn't actually exist in Python 2. I've tried using "excludes=urllib.parse?" as an argument to Analsys, but that doesn't seem to help.

Attachments

Change History

comment:1 Changed 15 months ago by matysek

This seems to be related to this mailing list thread: http://groups.google.com/group/pyinstaller/browse_thread/thread/af6a6339539e7d73

Citation:

I patched the iu.py so that it checks that fqname is in sys.modules before 
del'ing it and I can get it to build and run now.

comment:2 Changed 15 months ago by dn@…

Yea, I found that shortly after I submitted this. I took the other approach, and patched CherryPy? to not do the py3k detection.

comment:3 Changed 4 months ago by matysek

  • Status changed from new to closed
  • Resolution set to fixed

This should not be an issue anymore since latest dev version use PEP302 import machinery and not iu.py anymore.

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.