How to filter images on GAE?

225 views
Skip to first unread message

Computer_Engineer

unread,
Apr 17, 2012, 10:11:44 AM4/17/12
to google-a...@googlegroups.com
I'm working on python google app engine application,i'm using python2.5, i want to deal with images on GAE(filter images), initially i tried wit PIL library and i installed it successfully and i tested it and it works correctly on my computer,but when i test it on localhost(run on GAE), i have an error thatNotImplementedError: Unable to find the Python PIL library,then i tried to deal with images using Images Python API , as in this tutorial:https://developers.google.com/appengine/docs/python/images/overview, and i tested resizing images service,and it works correctly,but the main application that i want is to filter the images,the question is :if this service(image filtering) supported in Images Python API in GAE?and if not how can i filter images on GAE?i saw that this service available in PIL,but this library is not supported by GAE
I tried as a second choice to use python2.7 such that it supports PIL library and i edited the app.yaml configuration file,but i don't know how to use this library in the python page(main.py)?
app.yaml:
application: app_id
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /.*
  script: main.py
libraries:
- name: PIL
  version: "1.1.7"

...any suggestions are welcome...Thanks

Brian Quinlan

unread,
Apr 17, 2012, 4:16:06 PM4/17/12
to google-a...@googlegroups.com
Hi,

I'm going to address the Python 2.7 case since that is the best choice
for this problem.

You use PIL from main.py just like you would use PIL from any Python
script e.g.

import Image
i = Image.open(...)

In order to use Python 2.7 with the dev_appserver, you'll have to
install Python 2.7 and PIL on your computer.

Cheers,
Brian

>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/g48i1VaP0IUJ.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.

Computer_Engineer

unread,
Apr 18, 2012, 7:45:50 AM4/18/12
to google-a...@googlegroups.com
Brian Quinlan:Thanks for your response,i tried as :from PIL import Image , but the problem still as :No module named PIL
      args = ('No module named PIL',)
      message = 'No module named PIL'

Robert Kluin

unread,
Apr 18, 2012, 10:34:57 AM4/18/12
to google-a...@googlegroups.com
When you deploy to appspot, does your code work?

You need to use Python 2.7 locally, and you need to ensure PIL is
installed for Python 2.7.


Robert

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/google-appengine/-/f2BduRaG_CsJ.

Computer_Engineer

unread,
Apr 18, 2012, 12:53:08 PM4/18/12
to google-a...@googlegroups.com
Robert Kluin:
I firstly run my code on localhost to check errors.then i upload it to GAE,i use eclipse for working on python with GAE in windows, i installed python2.7 
and PIL version 1.1.7,then i edited the app.yaml,but the problem still,please i want a solution for this problem as soon as possible.
Thank you..


On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Brian Quinlan

unread,
Apr 18, 2012, 3:40:56 PM4/18/12
to google-a...@googlegroups.com
Hi,

On Thu, Apr 19, 2012 at 2:53 AM, Computer_Engineer <grou...@gmail.com> wrote:
> Robert Kluin:
> I firstly run my code on localhost to check errors.then i upload it to GAE,i
> use eclipse for working on python with GAE in windows, i installed
> python2.7
> and PIL version 1.1.7,then i edited the app.yaml,but the problem
> still,please i want a solution for this problem as soon as possible.
> Thank you..

In this case, could you try what Robert suggested and just upload your
application without running it locally to see if the problem is with
your code or with your local development environment?

If it works on the production system but not locally then you try
starting a Python shell and typing "import Image". If that doesn't
work then your PIL installation is not correct.

Cheers,
Brian

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/google-appengine/-/tmkdHRDGqAYJ.

Computer_Engineer

unread,
Apr 18, 2012, 3:56:45 PM4/18/12
to google-a...@googlegroups.com
Brian Quinlan: i tried to upload it into my application on GAE, the error still???what can i do?


On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Brian Quinlan

unread,
Apr 18, 2012, 4:51:44 PM4/18/12
to google-a...@googlegroups.com
Could you send the complete traceback?

Cheers,
Brian

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/google-appengine/-/Gy6_kxeqsY0J.

Robert Kluin

unread,
Apr 18, 2012, 4:52:29 PM4/18/12
to google-a...@googlegroups.com
I suggest you post your actual app.yaml and the full stack trace from
the appspot logs.

Robert

Computer_Engineer

unread,
Apr 18, 2012, 5:12:03 PM4/18/12
to google-a...@googlegroups.com

I provided my app.yaml in the question,and this is the trace:
INFO     2012-04-18 21:08:25,615 appengine_rpc.py:159] Server: appengine.google.com
INFO     2012-04-18 21:08:25,904 rdbms_sqlite.py:58] Connecting to SQLite database '' with file 'c:\\users\\me\\appdata\\local\\temp\\dev_appserver.rdbms'
INFO     2012-04-18 21:08:26,200 dev_appserver_multiprocess.py:637] Running application compressanddecompress on port 8080: http://localhost:8080
ERROR    2012-04-18 21:09:16,936 dev_appserver.py:4096] Exception encountered handling request
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 4039, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3945, in _Dispatch
    base_env_dict=env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 605, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3015, in Dispatch
    self._module_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2925, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2785, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\me\workspace\img_filter\helloworld.py", line 1, in <module>
    from PIL import Image
ImportError: No module named PIL
INFO     2012-04-18 21:09:16,938 dev_appserver.py:4143] "GET / HTTP/1.1" 500 -
ERROR    2012-04-18 21:09:17,328 dev_appserver.py:4096] Exception encountered handling request
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 4039, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3945, in _Dispatch
    base_env_dict=env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 605, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3015, in Dispatch
    self._module_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2925, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2785, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\me\workspace\img_filter\helloworld.py", line 1, in <module>
    from PIL import Image
ImportError: No module named PIL
INFO     2012-04-18 21:09:17,328 dev_appserver.py:4143] "GET /favicon.ico HTTP/1.1" 500 -
ERROR    2012-04-18 21:09:37,575 dev_appserver.py:4096] Exception encountered handling request
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 4039, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3945, in _Dispatch
    base_env_dict=env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 605, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3015, in Dispatch
    self._module_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2925, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2785, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\me\workspace\img_filter\helloworld.py", line 1, in <module>
    from PIL import Image
ImportError: No module named PIL
INFO     2012-04-18 21:09:37,576 dev_appserver.py:4143] "GET / HTTP/1.1" 500 -
ERROR    2012-04-18 21:09:37,904 dev_appserver.py:4096] Exception encountered handling request
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 4039, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3945, in _Dispatch
    base_env_dict=env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 605, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3015, in Dispatch
    self._module_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2925, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2785, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\me\workspace\img_filter\helloworld.py", line 1, in <module>
    from PIL import Image
ImportError: No module named PIL
INFO     2012-04-18 21:09:37,904 dev_appserver.py:4143] "GET /favicon.ico HTTP/1.1" 500 -

On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Brian Quinlan

unread,
Apr 18, 2012, 5:17:24 PM4/18/12
to google-a...@googlegroups.com
Hi,

Could you send the stack trace from production, not from your
development server?

Cheers,
Brian

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/google-appengine/-/ybmVHi70O0IJ.

Computer_Engineer

unread,
Apr 18, 2012, 5:27:09 PM4/18/12
to google-a...@googlegroups.com
Sorry,but how can i get the log file from the product?


On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Brian Quinlan

unread,
Apr 18, 2012, 5:30:40 PM4/18/12
to google-a...@googlegroups.com
On Thu, Apr 19, 2012 at 7:27 AM, Computer_Engineer <grou...@gmail.com> wrote:
> Sorry,but how can i get the log file from the product?

Go to the administration console (http://appengine.google.com), select
your application and then click "Logs".

Cheers,
Brian

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/google-appengine/-/CcIwSJCCDXEJ.

Computer_Engineer

unread,
Apr 18, 2012, 5:38:31 PM4/18/12
to google-a...@googlegroups.com
This is the log from the admin console log:
    1. 2012-04-18 14:37:10.162 /favicon.ico 500 666ms 0kb Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.67 Safari/534.13
      86.108.69.231 - - [18/Apr/2012:14:37:10 -0700] "GET /favicon.ico HTTP/1.1" 500 0 - "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.67 Safari/534.13" "filterimages2012.appspot.com" ms=667 cpu_ms=350 api_cpu_ms=0 cpm_usd=0.009764 instance=00c61b117c8fe6c4727b8c723b40c98b47e0df7f
    2. E2012-04-18 14:37:10.033
      Traceback (most recent call last):
        File "/base/data/home/apps/s~filterimages2012/1.358303610596814412/helloworld.py", line 7, in <module>
          out.save("2.jpg")
        File "/base/python27_runtime/python27_lib/versions/third_party/PIL-1.1.7/PIL/Image.py", line 1433, in save
          fp = __builtin__.open(fp, "wb")
      IOError: [Errno 13] Permission denied: '2.jpg'
      
    1. 2012-04-18 14:37:09.075 / 500 957ms 0kb Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.67 Safari/534.13
      86.108.69.231 - - [18/Apr/2012:14:37:09 -0700] "GET / HTTP/1.1" 500 0 - "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.67 Safari/534.13" "filterimages2012.appspot.com" ms=958 cpu_ms=467 api_cpu_ms=0 cpm_usd=0.013012 loading_request=1 instance=00c61b117c8fe6c4727b8c723b40c98b47e0df7f
    2. E2012-04-18 14:37:09.071
      Traceback (most recent call last):
        File "/base/data/home/apps/s~filterimages2012/1.358303610596814412/helloworld.py", line 7, in <module>
          out.save("2.jpg")
        File "/base/python27_runtime/python27_lib/versions/third_party/PIL-1.1.7/PIL/Image.py", line 1433, in save
          fp = __builtin__.open(fp, "wb")
      IOError: [Errno 13] Permission denied: '2.jpg'
      
    3. I2012-04-18 14:37:09.074
      This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.

On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Andreas

unread,
Apr 18, 2012, 5:41:23 PM4/18/12
to google-a...@googlegroups.com
you are trying to open a file. you can't do that. you dont have any access to the filesystem on gae.

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/Rk9EAnJyPIEJ.

Computer_Engineer

unread,
Apr 18, 2012, 5:42:56 PM4/18/12
to google-a...@googlegroups.com
Thanks very much for you Brian and Report,the error is from i error in access to files,this is no  problem,i can solve it ,really thanks.I discovered the problem from the log file.


On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Computer_Engineer

unread,
Apr 18, 2012, 5:45:17 PM4/18/12
to google-a...@googlegroups.com
aschmid: yes i i know that but i was thinking the problem from the PIL it self,until i see the log file,thank you for your response.


On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Brian Quinlan

unread,
Apr 18, 2012, 6:12:52 PM4/18/12
to google-a...@googlegroups.com
Hi Andreas,

On Thu, Apr 19, 2012 at 7:41 AM, Andreas <a.sch...@gmail.com> wrote:
> you are trying to open a file. you can't do that. you dont have any access
> to the filesystem on gae.

That is not true - you have access to a read-only file system
containing all of the files in the directory that you uploaded with
appcfg.py update (and don't appear in a "static" handler in your
app.yaml, doesn't match skip_files, etc.). The reason that this fails
is because the file is being opened for *write*, which is not
supported.

Cheers,
Brian

Computer_Engineer

unread,
Apr 19, 2012, 4:38:55 AM4/19/12
to google-a...@googlegroups.com
I want to filter images using GAE,firstly i stored the image in the blobstore as it's without changes, then i got the url for that image to open it then filter using PIL,the original image is stored correctly in the blobstore but i can't open it using the url how can i open it to filter? i tried as:
 url = images.get_serving_url(blob_key)
        imageFile = url
        im = Image.open(imageFile)
but this makes error.?


On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Computer_Engineer

unread,
Apr 19, 2012, 10:30:26 AM4/19/12
to google-a...@googlegroups.com
Please i want to ask how can i test the application locally before uploading it to GAE,how can i solve the PIL problem on localhost?and if i want to filter images using PIL i will open it  firstly,so my code initially let the user to upload his photo then i store this image in blobstorem and get the url of this image top open it,but this didn't solve the problem;that i can't open it?


On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:

Brian Quinlan

unread,
Apr 19, 2012, 4:01:44 PM4/19/12
to google-a...@googlegroups.com
Hi,

On Fri, Apr 20, 2012 at 12:30 AM, Computer_Engineer <grou...@gmail.com> wrote:
> Please i want to ask how can i test the application locally before uploading
> it to GAE,how can i solve the PIL problem on localhost?and if i want to
> filter images using PIL i will open it  firstly,so my code initially let the
> user to upload his photo then i store this image in blobstorem and get the
> url of this image top open it,but this didn't solve the problem;that i can't
> open it?

You might be better to ask search for the answer to these questions at
http://stackoverflow.com/ and, if you can't find one, to ask a new
one. The tag that you should use is "google-app-engine".

Cheers,
Brian

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/google-appengine/-/W3-vzVSeq94J.

Computer_Engineer

unread,
Apr 19, 2012, 4:15:14 PM4/19/12
to google-a...@googlegroups.com
Brian:
Thanks for your response, i can got the file and i opened it as :
im = Image.open(blob_info.open())
        out = im.filter(ImageFilter.EDGE_ENHANCE_MORE)
       
        
        u_file = files.blobstore.create(mime_type=m,_blobinfo_uploaded_filename=name)
        data=out
        with files.open(u_file, 'a') as f:
                f.write(data)
        files.finalize(u_file)
        blob_key = files.blobstore.get_blob_key(u_file)
such that the blob_info is the information about the original image in the blob store,but after filtering i can't store it on blobstore,i can't specify the correct value for data.

On Tuesday, April 17, 2012 5:11:44 PM UTC+3, Computer_Engineer wrote:
Reply all
Reply to author
Forward
0 new messages