Q:

Cannot import markdown because of COMMAND_LINE_LOGGING_LEVEL

I've got a weird error where I can import markdown in Python, and I can import markdown in python inside the Django runserver, but I get the following when trying to import markdown inside of gunicorn's app server.
* ImportError: cannot import name COMMAND_LINE_LOGGING_LEVEL
This is even more confusing because I found the only place where COMMAND_LINE_LOGGING_LEVEL is referenced in markdown (or any of the code I'm using) -- one line, defining it, in the markdown init.py, and I commented it out. I still get this error.
Any ideas?

A:

Gunicorn, for reasons I don't understand yet, adds the virtualenv/bin directory to the sys.path. Markdown installs a markdown.py into that bin directory. That markdown.py tries to import COMMAND_LINE_LOGGING_LEVEL from markdown the library. This results in a circular failure.
I don't know why Gunicorn does this, and probably it shouldn't. My convenience fix is to add the following to the server's local_settings.py
import sys
for i, path in enumerate(sys.path):
    if path.endswith('bin'):
        del sys.path[i]

