uwsgi + django:ImportError:没有名为OS的模块

时间:2015-02-04 09:15:36

标签: python django uwsgi

================更新===================

我试图从ini文件中注释掉home,pythonpath,virtualenv和env变量,并在我的wsgi.py中设置PYTHONPATH,如下所示:

os.environ.setdefault("PYTHONPATH", "/root/virtual_env")

但是,我收到了这个新错误:

> ImportError:没有名为django.core.wsgi的模块

因此,为了解决这个新问题,我创建了一个.pth文件并将其放在我的虚拟环境的网站包上(即 /root/virtual_env/lib/python2.7/site-packages )包含这个:

  

/root/virtual_env/lib/python2.7/site-packages/django

但是这样做之后,当我运行时,错误仍然存​​在../bin/uwsgi myproject_uwsgi.ini

===================== END OF UPDATE ==================== ==

在我的虚拟环境中(通过virtualenv),我仍然遇到了

  

ImportError:没有名为os的模块     无法加载应用0(mountpoint ='')(未找到可调用或导入错误)      *没有加载应用。进入完全动态模式*

当我运行../bin/uwsgi --ini myproject_uwsgi.ini时。以下是所述ini的完整内容。正如您在下面看到的,我已经回家了,pythonpath,virtualenv和env变量/参数,以逃避错误。不过,没有运气。我该怎么办?提前谢谢!

#myproject_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /root/virtual_env/myproject
# Django wsgi file
module          = myproject.wsgi:application
# the virtualenv (full path)
home            = /root/virtual_env/myproject
pythonpath      = /root/virtual_env/myproject
virtualenv      = /root/virtual_env/myproject
env             = DJANGO_SETTINGS_MODULE=myproject.settings

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 4
# the socket (use the full path to be safe
socket          = /root/virtual_env/myproject/myproject.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 777
chown-socket    = uwsgi:uwsgi
# clear environment on exit
vacuum          = true

# other config options
uid = uwsgi
gid = uwsgi
processes = 4
daemonize = /var/log/uwsgi/myproject.log
no-site = true

1 个答案:

答案 0 :(得分:0)

看来你的virtualenv存在问题。

pythonpathvirtualenv不应该相等。 Virtualenv应该在您项目的目录中。 例如,如果您的项目位于/ root / myproject中,那么您的virtualenv 应该在/ root / myproject / virtual_env中。 您的DJANGO_SETTINGS_MODULE也不正确。

毕竟你的uwsgi.ini应该是这样的:

#myproject_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /root/myproject
# Django wsgi file
module          = wsgi:application
# the virtualenv (full path)
home            = /root/myproject
pythonpath      = /root/myproject
virtualenv      = /root/myproject/virtual_env
env             = DJANGO_SETTINGS_MODULE=settings

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 4
# the socket (use the full path to be safe
socket          = /root/myproject/myproject.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 777
chown-socket    = uwsgi:uwsgi
# clear environment on exit
vacuum          = true

# other config options
uid = uwsgi
gid = uwsgi
processes = 4
daemonize = /var/log/uwsgi/myproject.log
no-site = true