I've recently deployed an application online using DigitalOcean single-click droplet setup which setup Django on Ubuntu with nginx and gunicorn. It came with a default django project which I've managed to change to my own. However, the default project doesn't use a virtualenv, it uses a system-wide install. So, the app only works if all the dependencies are installed on the system. I know this because if I uninstall django, it gives me an internal server error.
I would like to use the python in my virtualenv as the interpreter. And refer to the site-packages in that environment. I've tried fiddling with the PYTHONPATH and adding sys.path.append('/home/env/projectname') to the wsgi file but this doesn't work.
How can I achieve this?
/etc/init/gunicorn.conf:
setuid django
setgid django
chdir /home/env/projectname
exec gunicorn \
--name=prj \
--pythonpath=prj \
--bind=127.0.0.1:9000 \
--config /etc/gunicorn.d/gunicorn.py \
prj.wsgi:application
答案 0 :(得分:0)
现在,gunicorn是一个Python程序。 没有运行你的Django项目;它导入你的Django项目。所以你不可能在不同的环境中运行gunicorn和你的Django项目,因为它们实际上是一个程序。在特定的隔离环境中运行Django项目的方法是在孤立的环境中启动gunicorn:
source your_virtualenv_dir/bin/activate
exec gunicorn ...
要使其工作,您必须在virtualenv中安装gunicorn,或者您必须在系统范围内安装gunicorn并使用--system-site-packages
创建virtualenv。
答案 1 :(得分:0)
尝试将gunicorn安装到virtualenv并从那里运行它来设置工作目录并传递wsgi:application。 This tutorial可能会对您有所帮助。 This tutorial也可能有用。