A new blog on various actuarial stuffs...

The aim of this blog is sharing information of interest in the actuarial world. We consider informative contents as well as implementation tools in financial, life and pension actuarial matters.

Thursday, 27 January 2011

Python Web-Hosting with Numpy : virtualising your environment

Many solutions can be found to host a Python-based website. But really few (none?) of them offer a solutions with pre-installed Numpy, Scipy and Matplotlib. A way for circumeventing this seems to rely on the virtualisation of your Python environment with tools such virtualenv. You would have to proceed as follows
  1. Virtualisation of a own Python environment with the website hoster
  2. Installation of the required tools with easy_install
This link points to the referred solution (copied hereunder)...that I have not tested ! 

For your information:
  • I didn't know numpy, scipy and friends could be (easily) installed with easy_install
  • This at least requires the gcc tools or the corresponding compiling and building tools to be installed with the server

You can indeed install third party packages to your hosted space. If it's a pure python package, all that's needed is to unpack it to a directory and then add that directory to your PYTHONPATH environment variable or sys.path.
This can be tiring to do often, and won't work easily for compiled modules. If you have shell access to your python host, the excellent virtualenv package allows you to do set up a private python environment with its own libraries.
To set up your virtualenv, you'll do something like this at the shell:
$ virtualenv $HOME/my_python
$ $HOME/my_python/bin/easy_install numpy
You can keep running easy_install for anything else you want to install in your personal python environment.
Now, when you write your python scripts, you will want to use your private python interpreter, if that is possible:
 #!/home/myuser/my_python/bin/python
import numpy
# script here
If your python env cannot be specified (such as if run by mod_wsgi), you will need to add it to the  import path:
import sys
sys.path.insert(0, '/home/myuser/my_python/lib/python2.5/site-packages')
import numpy

No comments:

Post a Comment

Note: only a member of this blog may post a comment.