Workaround for google app engine’s – File not accessible error using virtualenv

Google App Engine comes really handy for devs who want to host their application idea/hack on google’s infrastructure without having to spend any $$ for it (and the resource limits are pretty descent for free account). No wonder it is a really useful tool that every developer/hacker should know of.

Few days earlier while trying to implement some pet project idea of mine at google app engine, I got a strange long exception(probably sandbox violation error) when I tried to access the running app engine application in my browser.

Here is the truncated traceback message (App engine internal function calls removed)

WARNING 2010-09-28 19:13:59,854] Can't open zipfile /usr/local/lib/python2.6/dist-packages/pyExcelerator-0.6.0a-py2.6.egg: IOError: [Errno 13] file not accessible: '/usr/local/lib/python2.6/dist-packages/pyExcelerator-0.6.0a-py2.6.egg'


File "/home/ashish/Desktop/google_appengine/google/appengine/tools/", line 2188, in ExecuteOrImportScript
exec module_code in script_module.__dict__
File "/home/ashish/Desktop/google_appengine/shuffler/", line 17, in
import cgi



File "/home/ashish/Desktop/google_appengine/google/appengine/tools/", line 1186, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/usr/local/lib/python2.6/dist-packages/cgi.unescape-0.0.2-py2.6.egg'
INFO 2010-09-28 19:13:59,865] "GET / HTTP/1.1" 500 -

I had no idea why I got this error as cgi module was available and even import cgi worked on python interpreter prompt. It looked like some kind of sandbox error as I knew google app engine runs application in a security sandbox. Googling for the error didn’t do much help. Maybe I screwed up directory permissions on my *nix system, or maybe the external python libraries present on my system are giving app engine a hard time.

I remembered from some time ago while working on Pylons, which is another nice pluggable python based web framework, that it recommended installing virtualenv as a part of pylons installation step.

virtualenv is a tool to create isolated Python environments. It comes quite handy when one want to install a python library/framework, while avoiding any side-effects to the existing python installation.

As a formal disclaimer, While this process should do no harm, still proceed with caution. Also Note that this has been ONLY tested with python version 2.6 on Ubuntu 10.04 OS.

sudo easy_install virtualenv==1.4.9 (Or if you prefer apt-get install or pip)

Assuming that :
1) You have python version 2.6 installed.
2) You want to install this separate python installation on ~/GAE_PYTHON directory.

Create the new python environment by running
virtualenv -v -p python2.6 –no-site-packages ~/GAE_PYTHON_ENV

Assuming that last step completed successfully.

Now run this command to switch to the new created python environment –
source ~/GAE_PYTHON_ENV/bin/activate

You should now see your shell prompt prefixed by (GAE_PYTHON_ENV) (Note: I Use bash shell)

If the process so far completed without any errors, try running any of the demo application that comes with Google APP engine (While remaining in the same environment ) to quickly check if the new setup works. I tried guestbook demo application that ships with app engine’s setup and was able to use it without any difficulties.

Note that now this setup doesn’t have access to python libraries that you may have installed on your base python setup, so you may need to install required libraries for this setup separately. You should be able to install any library in the usual way using easy_install or pip while working from within the new environment.

While this will probably work for the system I have described above, if you happen to have a different system setup, try looking for specific installation instructions on how to set up virtualenv on your system.

About Ashish Yadav

Hey there!!! I am Ashish Yadav, a Geek | Music Lover | Open Web enthusiast | Wannabe entrepreneur. I currently live in Chennai, India and share my thoughts, nifty hacks rather infrequently here with rest of the world. If you like my posts, may I suggest subscribing to the blog to read them as they are written :) . As a part of my day job I enjoy writing ubercool python code, and have loads of fun while at it. Opinions presented here are mine and not to be associated with my employer or anyone else. Opinions presented here are mine and not to be associated with my employer or anyone else.
This entry was posted in code, troubleshooting and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s