views:

133

answers:

4

I have developed a python CGI application which works just fine on my development box. My hosting provider however gives me little control of its server: I use a lot of custom stuff in my python environment (like sqlalchemy and mako templating) and the servers python version is far too old to be used. My question is: how do I set up a isolated, complete, standalone python environment in my home directory and install my required modules to run my app? ...the easiest way ;)

A: 

This looks like a job for virtualenv. From the site:

Also, what if you can't install packages into the global site-packages directory? For instance, on a shared host.

This looks to be right up your alley.

jathanism
I've found this myself and it's not what i need: I don't want to use the systems Python version... I need a separate environment with my own Python, not just different libs.
akosch
jathanism
sry if i was unclear: i can't use virtualenv or easy_install because they need python to work and I don't have a working python environment on that system. I need to set up python from scratch in my home dir
akosch
+1  A: 

In your shoes, I'd use pyinstaller to bundle Python, my code, and all my dependencies into one installer executable, upload it, and run it. Just be sure to use the SVN trunk of pyinstaller -- the "released" version is WAY obsolete.

Be aware that with SQLAlchemy and everything else, with CGI you may find out you're really slow, since you're paying the full startup price everytime the page gets visited. But if CGI is all you can afford, I guess that's the way I would try to cope!-)

Alex Martelli
A: 

I am on Dreamhost's shared plan. Besides CGI, they also offer FastCGI which makes things much faster than CGI. You should check if your hosting provider offers that. Or maybe they provide Passenger for Ruby that you could piggyback your Python with.

If you compile Python yourself, keep in mind the UCS setting if you try to install precompiled packages and experience failures. See the StackOverflow article. Dreamhost's wiki has some advice on how you could build and deploy Python yourself on their servers; you might want to adapt to your needs.

Heikki Toivonen
+2  A: 

how do I set up a isolated, complete, standalone python environment in my home directory

  1. mkdir /home/me/.local (if it doesn't already exist. You don't have to use .local but it is becoming the normal place to put this)
  2. mkdir /home/me/.local/src (ditto)
  3. cd /home/me/.local/src
  4. wget http://python.org/ftp/python/2.6.4/Python-2.6.4.tgz
  5. gzip -d Python-2.6.4.tgz
  6. tar xf Python-2.6.4.tar
  7. cd Python-2.6.4
  8. ./configure --prefix=/home/me/.local
  9. make
  10. make install

Hopefully you can now run Python:

  • /home/me/.local/bin/python

Install packages you need using the usual setup.py script, but with your version of Python:

  • /home/me/.local/bin/python setup.py install

Set hashbang on CGI files to use your version of Python:

  • #!/home/me/.local/bin/python

Consider migrating your application to WSGI if you can. You can of course still deploy WSGI apps through CGI using a wsgiref.handlers.CGIHandler for now, but in the future when you have a less woeful hosting environment you'll be able to deploy using a much less wasteful server interface such as mod_wsgi.

bobince
many thanks: this worked perfectly!
akosch