Tuesday, 8 April 2014

CherryPy - No module named wsgiserver2


The Problem
Trying to run CherryPy on Windows 7 64-bit with Python 2.7.x you might experience an error message on the form:

C:\cgi>python testCherrypy.py
[08/Apr/2014:12:12:35] ENGINE Listening for SIGTERM.
[08/Apr/2014:12:12:35] ENGINE Bus STARTING
[08/Apr/2014:12:12:35] ENGINE Set handler for console events.
CherryPy Checker:
The Application mounted at '' has an empty config.

[08/Apr/2014:12:12:35] ENGINE Started monitor thread 'Autoreloader'.
[08/Apr/2014:12:12:35] ENGINE Started monitor thread '_TimeoutMonitor'.
[08/Apr/2014:12:12:35] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x00000000031B45C0>>
Traceback (most recent call last):
  File "C:\prgFiles\Python27\lib\site-packages\cherrypy-3.2.5-py2.7-win-amd64.egg\cherrypy\process\wspbus.py", line 197, in publish
    output.append(listener(*args, **kwargs))
  File "C:\prgFiles\Python27\lib\site-packages\cherrypy-3.2.5-py2.7-win-amd64.egg\cherrypy\_cpserver.py", line 150, in start
    self.httpserver, self.bind_addr = self.httpserver_from_self()
  File "C:\prgFiles\Python27\lib\site-packages\cherrypy-3.2.5-py2.7-win-amd64.egg\cherrypy\_cpserver.py", line 140, in httpserver_from_self
    from cherrypy import _cpwsgi_server
  File "C:\prgFiles\Python27\lib\site-packages\cherrypy-3.2.5-py2.7-win-amd64.egg\cherrypy\_cpwsgi_server.py", line 7, in <module>
    from cherrypy import wsgiserver
  File "C:\prgFiles\Python27\lib\site-packages\cherrypy-3.2.5-py2.7-win-amd64.egg\cherrypy\wsgiserver\__init__.py", line 11, in <module>
    from wsgiserver2 import *
ImportError: No module named wsgiserver2

[08/Apr/2014:12:12:35] ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
  File "C:\prgFiles\Python27\lib\site-packages\cherrypy-3.2.5-py2.7-win-amd64.egg\cherrypy\process\wspbus.py", line 235, in start
    self.publish('start')
  File "C:\prgFiles\Python27\lib\site-packages\cherrypy-3.2.5-py2.7-win-amd64.egg\cherrypy\process\wspbus.py", line 215, in publish
    raise exc
ChannelFailures: ImportError('No module named wsgiserver2',)

[08/Apr/2014:12:12:35] ENGINE Bus STOPPING
[08/Apr/2014:12:12:35] ENGINE HTTP Server None already shut down
[08/Apr/2014:12:12:35] ENGINE Stopped thread 'Autoreloader'.
[08/Apr/2014:12:12:35] ENGINE Removed handler for console events.
[08/Apr/2014:12:12:35] ENGINE Stopped thread '_TimeoutMonitor'.
[08/Apr/2014:12:12:35] ENGINE Bus STOPPED
[08/Apr/2014:12:12:35] ENGINE Bus EXITING
[08/Apr/2014:12:12:35] ENGINE Bus EXITED

The Fix
The fix to this is simple:
1) Download wsgiserver2.py (alternative link).
2) Save this file to your `site-packages\cherrypy\wsgiserver` directory under your Python installation.

Example:

The Test
Running CherryPy should now work:
C:\cgi>python testCherrypy.py
[08/Apr/2014:12:30:00] ENGINE Listening for SIGTERM.
[08/Apr/2014:12:30:00] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.

[08/Apr/2014:12:30:00] ENGINE Set handler for console events.
[08/Apr/2014:12:30:00] ENGINE Started monitor thread '_TimeoutMonitor'.
[08/Apr/2014:12:30:00] ENGINE Started monitor thread 'Autoreloader'.
[08/Apr/2014:12:30:01] ENGINE Serving on 127.0.0.1:8818
[08/Apr/2014:12:30:01] ENGINE Bus STARTED

Links
other sources about same issue
https://github.com/zacharyvoase/markdoc/issues/31
https://bitbucket.org/cherrypy/cherrypy/issue/1110/cherrypy-322win32exe-installer-didnt
http://stackoverflow.com/questions/13638796/cherrypy-running-tut01-file-on-windows



4 comments:

  1. Thanks for posting your experience, as I also had this problem.

    But I recommend an alternative solution. Apparently the pip install package is broken. You can force it to work with:
    pip install --no-use-wheel CherryPy

    You might want to start with:
    pip uninstall CherryPy
    Since you must have already installed it if you see this problem.

    All credit goes to "cdent" here

    ReplyDelete
    Replies
    1. Thanks for shedding new light on this problem, JB!

      Delete
    2. Thanks JB! Really helped :)

      Delete

Allowed HTML tags:
<b>bold</b>
<strong>strong</strong>
<i>italics</i>
<em>emphasis</em>
<a href="">hyperlink</a>


Please, show the courtesy of identifying yourself when adding a comment. Anonymous comments will, most likely, be removed.