简体   繁体   English

uwsgi + django导入错误

[英]uwsgi + django import error

I have a problem when I use django with uwsgi with the pythonpath. 将Django与uwsgi与pythonpath一起使用时出现问题。

I have a django project named 'project' which is the /sites/django/ directory 我有一个名为'project'的django项目,它是/ sites / django /目录

So to start uwsgi i use this command : 因此,要启动uwsgi,请使用以下命令:

/opt/uwsgi/uwsgi -s 127.0.0.1:9001 -C -M 4 -t 30 -A 4 -p 4 -d /var/log/uwsgi.log --pythonpath '/sites/django/project/' --module wsgi

If I am in the /sites/django/project' it works. 如果我在/ sites / django / project中,则可以使用。

If I start a python shell and I write : 如果我启动python shell并编写:

import sys
sys.path.append('/sites/django/project/')
import wsgi

It works too. 它也可以。

But when i launch the uwsgi command outside the /sites/django/project/ I have the error : 但是当我在/ sites / django / project /之外启动uwsgi命令时,出现错误:

ImportError: No module named wsgi ImportError:没有名为wsgi的模块

So I don't know why I have the ImportError : it works in the shell. 所以我不知道为什么会有ImportError:它可以在外壳中工作。

If anyone has an idea, Thanks. 如果有人有主意,谢谢。

Well, i find the answer, it seems it's a bug and i must add the "-i" option (single interpreter mode ) in my command . 好吧,我找到了答案,似乎是一个错误,我必须在命令中添加“ -i”选项(单解释器模式)。

The documentation seems to suggest two possibilities. 文档似乎暗示了两种可能性。

First, remove the single quotes from the python path argument. 首先,从python路径参数中删除单引号。 Second, the examples on the linked page have --python-path instead of --pythonpath (even though the index at the top of the page says otherwise). 其次,链接页面上的示例使用--python-path而不是--pythonpath (即使页面顶部的索引另有说明)。 Worth trying. 值得尝试。

如果您使用的是virtualenv,则需要传递-H标志( http://projects.unbit.it/uwsgi/wiki/VirtualEnv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM