uwsgi ImportError:没有名为os的模块

我教自己如何设置一个Ubuntu服务器来运行我的Django应用程序。 我想使用Nginx + uwsgi。 我知道这个问题对于专家来说可能非常简单,但是我已经花了6天的时间在网上查找,但是没有得到它(在任何情况下,如果答案中有任何链接,请原谅我)。 我跟着很多教程和post,但我没有find一个解决scheme。

我在下面描述我的文件结构:

我的django项目位于/ usr / local / projects / myproject

我的virtualenv在/root/.virtualenvs/myproject

我的uwsgiconfiguration文件myproject.ini位于/ etc / uwsgi / apps-available /中,正确符号链接在/ etc / uwsgi / apps-enabled /

[uwsgi] plugins = python socket = /tmp/myproject.sock chmod-socket = 644 uid = www-data gid = www-data master = true enable-threads = true processes = 2 no-site=true virtualenv = /root/.virtualenvs/myproject chdir = /usr/local/projects/myproject module = myproject.wsgi:application pidfile = /usr/local/projects/myproject/myproject.pid logto = /var/log/uwsgi/myproject_uwsgi.log vacuum = true 

我的nginxconfiguration文件myproject.conf位于/ etc / nginx / sites-available /中,正确的符号链接在/ etc / nginx / sites-enabled /

 # the upstream component nginx needs to connect to upstream django { server unix:///tmp/myproject.sock; # for a file socket } server { listen 80; server_name dev.myproject.com www.dev.myproject.com; access_log /var/log/nginx/myproject_access.log; error_log /var/log/nginx/myproject_error.log; location / { uwsgi_pass unix:///tmp/myproject.sock; include /etc/nginx/uwsgi_params; uwsgi_param UWSGI_SCRIPT myproject.wsgi; } location /media/ { alias /usr/local/projects/myproject/media/; } location /static/ { alias /usr/local/projects/myproject/static/; } } 

当我尝试访问dev.myproject.com时,出现内部服务器错误。 然后我看看我的uwsgi日志:

 Traceback (most recent call last): File "./myproject/wsgi.py", line 9, in <module> import os ImportError: No module named os Sat Jul 26 17:39:16 2014 - unable to load app 0 (mountpoint='') (callable not found or import error) Sat Jul 26 17:39:16 2014 - --- no python application found, check your startup logs for errors --- [pid: 8559|app: -1|req: -1/8] 79.148.138.10 () {40 vars in 685 bytes} [Sat Jul 26 17:39:16 2014] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0) 

我需要你的帮助,因为我不能find一个解决scheme,尽pipe是非常简单的可能性。

如果您需要了解其他信息,请告诉我,我会尽快更新我的问题。

我终于找到了解决办法。

我遵循kchan的建议,不把任何内容放在/ root /目录中。 基本上,我在myproject.conf文件和我的myproject.ini文件中做了一些小的改动。 我创建了一个用户,并构建如下所示的一切:

uwsgi配置文件myproject.ini位于/ etc / uwsgi / apps-available /中,正确符号链接在/ etc / uwsgi / apps-enabled /

 [uwsgi] plugins = python socket = /tmp/myproject.sock chmod-socket = 644 uid = www-data gid = www-data master = true enable-threads = true processes = 2 virtualenv = /home/user/.virtualenvs/myproject chdir = /home/user/projects/myproject module = myproject.wsgi:application pidfile = /home/user/projects/myproject/myproject.pid daemonize = /var/log/uwsgi/myproject_uwsgi.log vacuum = true 

nginx配置文件myproject.conf在/ etc / nginx / sites-available /中正确符号链接在/ etc / nginx / sites-enabled /

 # the upstream component nginx needs to connect to upstream django { server unix:///tmp/myproject.sock; # for a file socket } server { listen 80; server_name dev.myproject.com www.dev.myproject.com; access_log /var/log/nginx/myproject_access.log; error_log /var/log/nginx/myproject_error.log; location / { uwsgi_pass django; include /etc/nginx/uwsgi_params; } location /media/ { alias /home/user/projects/myproject/media/; } location /static/ { alias /home/user/projects/myproject/static/; } } 

我必须说,我认为真正的问题是尝试在我的virtualenv的postactivate文件中设置我的数据库配置。 希望能帮助别人。