在OS X上设置Python Web开发环境

时间:2021-05-21 23:32:42

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.

我正在运行Mac OS X Leopard并想知道在我的机器上设置Web开发环境以便使用Python,MySQL,Apache的简单方法,这将允许我在我的Mac上进行开发,然后轻松地将其移动到主机中未来。

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?

我一直试图安装mod_wsgi并配置为与Django一起工作并且现在头疼。有没有任何网络主机,除了谷歌目前使用mod_wsgi,所以我可以在那里开发?

10 个解决方案

#1


2  

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.

FWIW,我们发现virtualenv [http://pypi.python.org/pypi/virtualenv]是我们开发设置中非常宝贵的一部分。我们通常使用不同版本的Python库等多个项目。如果没有某种方式提供本地化的自定义Python环境,就很难在一台机器上执行此操作,就像virtualenv那样。

#2


2  

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.

大多数Python应用程序正在远离mod_python。它可能因框架或提供程序而异,但大多数开发工作都会进入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.

使用WSGI标准将使您的Python应用程序服务器不可知,并允许其他很好的添加,如WSGI中间件。其他提供商可能只提供CGI(不能很好地扩展性能)或FastCGI。

#3


1  

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.

我已经使用了Django,只使用了manager.py脚本中包含的服务器,并且在转移到生产环境时没有遇到任何麻烦。

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.

如果将应用程序放在为您执行环境配置的主机中(例如WebFaction),则不应该有从开发到生产的问题。

#4


1  

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.

我在Mac笔记本电脑上运行Linux虚拟机。这使我可以保持我的开发环境和生产环境完全同步(并创建快照以便于实验/回滚)。我发现VMWare Fusion工作效果最好,但是如果你只是想弄湿你的话,还有免费的开源替代品,比如VirtualBox。

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).

我在Mac上的来宾Linux操作系统*享源文件夹,并使用我选择的Mac源编辑器编辑它们(我使用Eclipse / PyDev,因为其他优秀的TextMate还不能很好地处理中文文本)。我在这里记录了来宾Linux操作系统的软件设置;它针对多个Django应用程序(包括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.

为了增加额外的乐趣,您可以编辑Mac的/ etc / hosts文件,使yourdomainname.com解析为您的客户Linux机箱内部IP地址,并有一个简单的方法在线或离线工作/测试多个Web项目,而不会有太多麻烦。

#5


0  

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

您正在寻找的是Mod_Python。它是Python的基于Apache的解释器。看看这里:

http://www.modpython.org/

#6


0  

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

Google App Engine已经为您完成了。一些限制,但它工作得很好,它为您提供免费托管的途径。

#7


0  

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.

当然,Mac OS X在最近的版本中附带了Python和Apache。但是,您可能希望在所使用的版本中具有更大的灵活性,或者您可能不喜欢Apple对其配置方式所做的调整。获得更通用的工具集(包括MySQL)的好方法是重新安装它们。这将有助于您的可移植性问题。可以使用这些开源软件包提供程序之一相对容易地安装框架。

#8


0  

mod_wsgi is really, really simple.

mod_wsgi非常非常简单。

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.

Pyerweb是一个非常简单的(约90行,包括注释/空格)我写的WSGI兼容的路由框架。基本上,WSGI API只是一个通过environ和wsgi_start_response传递的函数,它返回一个字符串。

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

envrion是带有请求信息的字典,例如environ ['PATH_INFO']是请求URI)

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

wsgi_start_response是一个可调用的函数,你执行它来设置标题,:

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)

output_response是包含您要发送的HTTP状态的字符串(200 OK等),output_headers是包含您的标题的元组列表(例如,[(“Content-type”,“text / html”)]将设置内容类型)

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.

要运行它,使用产卵你可以做spawn scriptname.my_wsgi_function_nae,它将开始监听端口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

要通过mod_wsgi使用它,它的文档很好,http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide并且有一个django特定部分

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!

使用mod_wsgi的好处是它是服务Python Web应用程序的标准。我最近决定使用Google App Engine,当Pyerweb(我在这个答案开始时链接到的)完全无意中完美地工作时,我感到很惊讶。当我注意到Django应用程序运行时,我印象更深刻。标准化是一件好事!

#9


0  

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.

您可能想要查看web2py。它包括一个通过浏览器开发的管理界面。您只需要一个包,包括Python。

#10


0  

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.

查看WebFaction - 尽管我不使用它们(我也不会以任何方式与其业务相关/获利)。我一遍又一遍地阅读他们的服务有多棒,尤其是Django友好的方式。他们的论坛中有一篇关于启动和运行Django和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.

像我之前的其他人一样,我强烈建议使用Ian Bicking的virtualenv来隔离你的开发环境; mod_wsgi文档中有一个专用页面,用于完全相同的设置。

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:

我还恳请你查看pip,这基本上是一个更聪明的easy_install,它知道virtualenv。 Pip为virtualenv式开发做了两件非常好的事情:

  • Knows how to install from source control (SVN, Git, etc...)
  • 知道如何从源代码控制(SVN,Git等)安装...

  • 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.
  • 知道如何“冻结”现有开发环境的要求,以便您可以在其他地方创建该环境 - 非常适合多个开发人员或部署。

#1


2  

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.

FWIW,我们发现virtualenv [http://pypi.python.org/pypi/virtualenv]是我们开发设置中非常宝贵的一部分。我们通常使用不同版本的Python库等多个项目。如果没有某种方式提供本地化的自定义Python环境,就很难在一台机器上执行此操作,就像virtualenv那样。

#2


2  

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.

大多数Python应用程序正在远离mod_python。它可能因框架或提供程序而异,但大多数开发工作都会进入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.

使用WSGI标准将使您的Python应用程序服务器不可知,并允许其他很好的添加,如WSGI中间件。其他提供商可能只提供CGI(不能很好地扩展性能)或FastCGI。

#3


1  

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.

我已经使用了Django,只使用了manager.py脚本中包含的服务器,并且在转移到生产环境时没有遇到任何麻烦。

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.

如果将应用程序放在为您执行环境配置的主机中(例如WebFaction),则不应该有从开发到生产的问题。

#4


1  

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.

我在Mac笔记本电脑上运行Linux虚拟机。这使我可以保持我的开发环境和生产环境完全同步(并创建快照以便于实验/回滚)。我发现VMWare Fusion工作效果最好,但是如果你只是想弄湿你的话,还有免费的开源替代品,比如VirtualBox。

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).

我在Mac上的来宾Linux操作系统*享源文件夹,并使用我选择的Mac源编辑器编辑它们(我使用Eclipse / PyDev,因为其他优秀的TextMate还不能很好地处理中文文本)。我在这里记录了来宾Linux操作系统的软件设置;它针对多个Django应用程序(包括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.

为了增加额外的乐趣,您可以编辑Mac的/ etc / hosts文件,使yourdomainname.com解析为您的客户Linux机箱内部IP地址,并有一个简单的方法在线或离线工作/测试多个Web项目,而不会有太多麻烦。

#5


0  

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

您正在寻找的是Mod_Python。它是Python的基于Apache的解释器。看看这里:

http://www.modpython.org/

#6


0  

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

Google App Engine已经为您完成了。一些限制,但它工作得很好,它为您提供免费托管的途径。

#7


0  

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.

当然,Mac OS X在最近的版本中附带了Python和Apache。但是,您可能希望在所使用的版本中具有更大的灵活性,或者您可能不喜欢Apple对其配置方式所做的调整。获得更通用的工具集(包括MySQL)的好方法是重新安装它们。这将有助于您的可移植性问题。可以使用这些开源软件包提供程序之一相对容易地安装框架。

#8


0  

mod_wsgi is really, really simple.

mod_wsgi非常非常简单。

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.

Pyerweb是一个非常简单的(约90行,包括注释/空格)我写的WSGI兼容的路由框架。基本上,WSGI API只是一个通过environ和wsgi_start_response传递的函数,它返回一个字符串。

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

envrion是带有请求信息的字典,例如environ ['PATH_INFO']是请求URI)

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

wsgi_start_response是一个可调用的函数,你执行它来设置标题,:

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)

output_response是包含您要发送的HTTP状态的字符串(200 OK等),output_headers是包含您的标题的元组列表(例如,[(“Content-type”,“text / html”)]将设置内容类型)

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.

要运行它,使用产卵你可以做spawn scriptname.my_wsgi_function_nae,它将开始监听端口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

要通过mod_wsgi使用它,它的文档很好,http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide并且有一个django特定部分

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!

使用mod_wsgi的好处是它是服务Python Web应用程序的标准。我最近决定使用Google App Engine,当Pyerweb(我在这个答案开始时链接到的)完全无意中完美地工作时,我感到很惊讶。当我注意到Django应用程序运行时,我印象更深刻。标准化是一件好事!

#9


0  

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.

您可能想要查看web2py。它包括一个通过浏览器开发的管理界面。您只需要一个包,包括Python。

#10


0  

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.

查看WebFaction - 尽管我不使用它们(我也不会以任何方式与其业务相关/获利)。我一遍又一遍地阅读他们的服务有多棒,尤其是Django友好的方式。他们的论坛中有一篇关于启动和运行Django和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.

像我之前的其他人一样,我强烈建议使用Ian Bicking的virtualenv来隔离你的开发环境; mod_wsgi文档中有一个专用页面,用于完全相同的设置。

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:

我还恳请你查看pip,这基本上是一个更聪明的easy_install,它知道virtualenv。 Pip为virtualenv式开发做了两件非常好的事情:

  • Knows how to install from source control (SVN, Git, etc...)
  • 知道如何从源代码控制(SVN,Git等)安装...

  • 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.
  • 知道如何“冻结”现有开发环境的要求,以便您可以在其他地方创建该环境 - 非常适合多个开发人员或部署。