Posts tagged with: virtualenv

玩转浪点之打造自己的django环境

2009/08/15 – 00:45

说明: 虽然本文是针对django而写,但对于其他python框架应同样适用。 浪点现在只支持mod_python这一种部署方式了,详细了解mod_python请参考mod_python 官方手册翻译

构造虚拟环境:

$ python virtualenv.py –no-site-packages sandbox

virtualenv.py下载地址

浪点默认装了一些有用的Python包,如PIL、lxml等,这些依赖c的包是你无法自己在virtualenv环境中使用的,不过好在直接拷贝过来就可以用了

$ cp /usr/share/pyshared/* -r sandbox/lib/python2.6/site-packages/

切换到虚拟环境,安装自己的包

source sandbox/bin/activate easy_install Django

自定义Pythonhandler:

这里做的最核心的事情就相当于你运行source bin/activate,把Python运行环境切换为你自己的虚拟环境。

#myve.py activate_this = ‘/home/virtualhost/${username}/sandbox/bin/activate_this.py’ execfile(activate_this, dict(__file__=activate_this)) from django.core.handlers.modpython import handler

配置 .htaccess

注意这里的mysite和project。PythonInterpreter可随意写,只要别和其他目录下重复就行了,不写也可以

SetHandler python-program PythonPath "['/home/virtualhost/${username}/sandbox/bin', '/home/virtualhost/${username}/xmu.me/public_html/${mysite}/'] + sys.path" PythonHandler myve SetEnv DJANGO_SETTINGS_MODULE {project}.settings PythonDebug On PythonInterpreter wayhome

现在你就可以访问你的django程序了,have fun :) 如果你喜欢这篇文章,欢迎 订阅我的 RSS feed!

By youngking | Posted in Tech | Also tagged , , | Comments (0)