Brandon
Brandon

Reputation:

Setting up a Python web development environment on OS X

I'm running Mac OS X Leopard and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the future.

I've been trying to get mod_wsgi installed and configured to work with Django and have a headache now. Are there any web hosts that currently use mod_wsgi besides Google, so I could just develop there?

Upvotes: 2

Views: 1896

Answers (10)

Idan Gazit
Idan Gazit

Reputation: 2560

Check out WebFaction—although I don't use them (nor am I related to / profit from their business in any way). I've read over and over how great their service is and particularly how Django-friendly they are. There's a specific post in their forums about getting up and running with Django and mod_wsgi.

Like others before me in this thread, I highly recommend using Ian Bicking's virtualenv to isolate your development environment; there's a dedicated page in the mod_wsgi documentation for exactly that sort of setup.

I'd also urge you to check out pip, which is basically a smarter easy_install which knows about virtualenv. Pip does two really nice things for virtualenv-style development:

  • Knows how to install from source control (SVN, Git, etc...)
  • Knows how to "freeze" an existing development environement's requirements so that you can create that environment somewhere else—very very nice for multiple developers or deployment.

Upvotes: 0

2snacc
2snacc

Reputation: 6353

I run a Linux virtual machine on my Mac laptop. This allows me to keep my development environment and production environments perfectly in sync (and make snapshots for easy experimentation / rollback). I've found VMWare Fusion works the best, but there are free open source alternatives such as VirtualBox if you just want to get your feet wet.

I share the source folders from the guest Linux operating system on my Mac and edit them with the Mac source editor of my choosing (I use Eclipse / PyDev because the otherwise excellent TextMate doesn't deal well with Chinese text yet). I've documented the software setup for the guest Linux operating system here; it's optimized for serving multiple Django applications (including geodjango).

For extra added fun, you can edit your Mac's /etc/hosts file to make yourdomainname.com resolve to your guest Linux boxes internal IP address and have a simple way to work on / test multiple web projects online or offline without too much hassle.

Upvotes: 1

massimo
massimo

Reputation: 2775

You may want to look into web2py. It includes an administration interface to develop via your browser. All you need in one package, including Python.

Upvotes: 0

Null303
Null303

Reputation: 1042

I've worked with Django using only the included server in the manager.py script and have not had any trouble moving to a production environment.

If you put your application in a host that does the environment configuration for you (like WebFaction) you should not have problems moving from development to production.

Upvotes: 1

Mr_Pink
Mr_Pink

Reputation: 109336

Most Python applications are moving away from mod_python. It can vary by framework or provider, but most development effort is going into mod_wsgi.

Using the WSGI standard will make your Python application server agnostic, and allow for other nice additions like WSGI middleware. Other providers may only provide CGI (which won't scale well performance wise), or FastCGI.

Upvotes: 2

dbr
dbr

Reputation: 169543

mod_wsgi is really, really simple.

Pyerweb is a really simple (~90 lines including comments/whitespace) WSGI-compliant routing-framework I wrote. Basically the WSGI API is just a function that gets passed environ, and wsgi_start_response, and it returns a string.

envrion is a dict with the request info, for example environ['PATH_INFO'] is the request URI)

wsgi_start_response which is a callable function which you execute to set the headers,:

wsgi_start_response(output_response, output_headers)

output_response is the string containing the HTTP status you wish to send (200 OK etc), and output_headers is a list-of-tuples containing your headers (for example, [("Content-type", "text/html")] would set the content-type)

Then the function returns a string containing your output.. That's all there is to it!

To run it, using spawning you can just do spawn scriptname.my_wsgi_function_nae and it will start listening on port 8080.

To use it via mod_wsgi, it's documentation is good, http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide and there is a django specific section

The up-side to using mod_wsgi is it's the standard for serving Python web-applications. I recently decided to play with Google App Engine, and was surprised when Pyerweb (which I linked to at the start of this answer) worked perfectly on it, completely unintentionally. I was even more impressed when I noticed Django applications run on it too.. Standardisation is a good thing!

Upvotes: 0

psj
psj

Reputation: 164

FWIW, we've found virtualenv [http://pypi.python.org/pypi/virtualenv] to be an invaluable part of our dev setup. We typically work on multiple projects that use different versions of Python libraries etc. It's very difficult to do this on one machine without some way to provide a localized, customized Python environment, as virtualenv does.

Upvotes: 2

Glenn
Glenn

Reputation: 6563

Of course Mac OS X, in recent versions, comes with Python and Apache. However you may want to have more flexibility in the versions you use, or you may not like the tweaks Apple has made to the way they are configured. A good way to get a more generic set of tools, including MySQL, is to install them anew. This will help your portability issues. The frameworks can be installed relatively easily with one of these open source package providers.

Upvotes: 0

slf
slf

Reputation: 22767

Google App Engine has done it for you. Some limitations but it works great, and it gives you a path to hosting free.

Upvotes: 0

Robert Elwell
Robert Elwell

Reputation: 6668

What you're looking for is Mod_Python. It's an Apache-based interpreter for Python. Check it out here:

http://www.modpython.org/

Upvotes: 0

Related Questions