Python script just printing out blank page
Question: I am using xampp and I am able to run simple python script on it so xampp is
setup fine for python. I am trying to use pillow.

I have installed anaconda and did following in terminal

    
    
     conda install pillow
    

If I run test.py below in terminal, it works fine. It prints format, size,
mode.

But if I try it from web browser I'm getting blank page.

Here is test.py

    
    
    #!/Library/Frameworks/anaconda/bin/python
    
    print("Content-Type: text/html")
    print()
    print("<html><head><title>Python</title></head><body>")
    from PIL import Image, ImageFilter
    original = Image.open("Lenna.png")
    print("<h5>The size of the Image is: </h5>")
    print("<h2>size " + original.format, original.size, original.mode + "</h2>")
    

if I use cgitb.enable() I get following error

    
    
        A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
    
     /Applications/XAMPP/xamppfiles/cgi-bin/test7.py in ()
          8 print("<html><head><title>Python</title></head><body>");
          9 print("<h5>The size of the Image is: </h5>");
    =>   10 from PIL import Image
         11 original = Image.open("Lenna.png");
         12 width, height = original.size;
    PIL undefined, Image undefined
     /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/Image.py in ()
         61     # Also note that Image.core is not a publicly documented interface,
         62     # and should be considered private and subject to change.
    =>   63     from PIL import _imaging as core
         64     if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
         65         raise ImportError("The _imaging extension was built for another "
    PIL undefined, _imaging undefined, core = <PIL.Image._imaging_not_installed object>
    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/_imaging.so, 2): Library not loaded: @loader_path/.dylibs/libtiff.5.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/_imaging.so Reason: Incompatible library version: _imaging.so requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0 
          args = ('dlopen(/Library/Frameworks/Python.framework/Vers...later, but libtiff.5.dylib provides version 6.0.0',) 
          msg = 'dlopen(/Library/Frameworks/Python.framework/Vers...later, but libtiff.5.dylib provides version 6.0.0' 
          name = '_imaging' 
          path = '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PIL/_imaging.so' 
          with_traceback = <built-in method with_traceback of ImportError object>
    


Answer: Kind of an anti-answer, but unless you are doing it this way for academic
reasons, you should try one of the more standard frameworks:

  * [Flask](http://flask.pocoo.org/docs/0.10/quickstart/)
  * [bottle.py](http://bottlepy.org/docs/dev/index.html)

The two frameworks I listed above are examples of minimalist frameworks that
do not get in your way. They take care of running your app and setting up
routes. The minimum to use Flask is this:

    
    
    from flask import Flask
    from PIL import Image, ImageFilter
    
    app = Flask(__name__)
    
    @app.route("/")
    def myview():
        original = Image.open("Lenna.png")
    
        return """
            <html><head><title>Python</title></head>
            <body>
            <h5>The size of the Image is: </h5>
            <h2>size {format}, {size}, {mode}</h2>
            </body></html>""".format(
                format=original.format,
                size=original.size,
                mode=original.mode)
    
    app.run()
    

Next, if you want to make your app available, you only need to setup a reverse
proxy in XAMPP (easy-peasy). I highly suggest using Flask; it comes with an
awesome in-page debugger, courtesy of its sister project
[Werkzeug](http://werkzeug.pocoo.org/) (lit. "toolbox").

## Werkzeug debugger:

![Werkzeug debugger](http://i.stack.imgur.com/gIjr0.png)

