django uwsgi没有名为site的模块

时间:2017-09-17 07:00:32

标签: python django pip uwsgi wsgi

首先,我意识到存在许多相关问题,但没有一个能解决我的问题。 当我的virtualenv被激活时,我在centOs 7上使用sudo pip3 install uwsgi安装了uwsgi。我尝试用命令

运行它
uwsgi --http :8000 --module ashpazi.wsgi --ini ../ini_files/ashpazi.ini 

我收到此错误

ImportError: No module named site

这是我的ashpazi.ini文件

[uwsgi]
chdir = /root/projects/ashpazi
home  = /root/projects/venv
module = ashpazi.wsgi:application

master = true
processes = 5

uid = root
gid = nginx
env = DJANGO_SETTINGS_MODULE=ashpazi.settings
plugin = python3.6
socket = /root/projects/sockets/ashapazi.sock
chmod-socket = 777
vacuum = true

正在运行which uwsgi会返回不在virtualenv目录中的/usr/bin/uwsgi

运行sudo pip3 show uwsgi会返回:

Name: uWSGI
Version: 2.0.15
Summary: The uWSGI server
Home-page: https://uwsgi-docs.readthedocs.io/en/latest/
Author: Unbit
Author-email: info@unbit.it
License: GPL2
Location: /usr/lib/python2.7/site-packages

指出uwsgi位于python2.7文件夹中而不是python3.6我在我的django项目中使用。 我该如何解决这个问题?

修改
我使用sudo pip3 install uwsgi,因为在没有sudo的情况下使用它会导致此错误

*** uWSGI compiling embedded plugins ***
[gcc -pthread] plugins/python/python_plugin.o
In file included from plugins/python/python_plugin.c:1:0:
plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file 

or directory
 #include <Python.h>
                ^
    compilation terminated.

----------------------------------------
Command "/root/projects/venv/bin/python3.6 -u -c "import setuptools, 
tokenize;__file__='/tmp/pip-build-
yz2o1zz3/uwsgi/setup.py';f=getattr(tokenize, 'open', open)
(__file__);code=f.read().replace('\r\n', 
'\n');f.close();exec(compile(code, __file__, 'exec'))" install --record 
/tmp/pip-o6hcf_v3-record/install-record.txt --single-version-
externally-managed --compile --install-headers 
/root/projects/venv/include/site/python3.6/uwsgi" failed with error 
code 1 in /tmp/pip-build-yz2o1zz3/uwsgi/

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我的解决方案是使用python版本安装python-devel。例子python36u你必须安装python36u-devel然后安装“pip3.6 install uwsgi”。

答案 1 :(得分:0)

最后我想通了。为了在pip3中使用uwsgi,我必须先安装python36u-devel。现在uwsgi安装在venv目录中。

removing all existing uwsgi packages installed from pip or system package manager
sudo yum install python36u-devel
. venv/bin/activate (using virtual envirement to avoid installing it globally)
pip3 install uwsgi