ImportError: No module named 'django' uWSGI Django Nginx Ubuntu 16.04 Python3.6
ImportError: No module named 'django' uWSGI Django Nginx Ubuntu 16.04 Python3.6
我花了一天时间想弄明白。
我运行正在 Digital Ocean
与 Django
、Python3.6
、Nginx
、Ubuntu 16.04
和 uWSGI
.
必须通过 deadsnakesppa
安装 Python3.6
并且有一个 virtualenv
我用
创建的
mkvirtualenv --python=python3.6 myproject
我正在关注 this tutorial 我之前已经关注但是当我尝试 运行 下面的代码来测试应用程序服务器(不在 virtualenv 中)
uwsgi --http :8080 --home /home/user/Env/myproject --chdir /home/user/myproject/src/myproject -w myproject.wsgi
我得到这个回溯
*** Starting uWSGI 2.0.18 (64bit) on [Mon Aug 5 12:23:53 2019] ***
compiled with version: 5.4.0 20160609 on 05 August 2019 11:53:48
os: Linux-4.4.0-157-generic #185-Ubuntu SMP Tue Jul 23 09:17:01 UTC 2019
nodename: myproject
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/user/myproject/src/myproject
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3898
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8080 fd 4
spawned uWSGI http 1 (pid: 17338)
uwsgi socket 0 bound to TCP address 127.0.0.1:34660 (port auto-assigned) fd 3
Python version: 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x21aaf90
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./myproject/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named 'django'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 17337, cores: 1)
当我激活 virtualenv 时,我得到了同样的结果。
更多错误日志是
Aug 05 12:18:20 myproject uwsgi[16998]: --- no python application found, check your system...
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Main process exited, code=exited, status=203/EXEC
Aug 05 11:39:47 myproject systemd[1]: Failed to start uWSGI Emperor service.
Aug 05 11:39:47 wmyproject systemd[1]: uwsgi.service: Unit entered failed state.
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Failed with result 'exit-code'.
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Service hold-off time over, scheduling restart.
Aug 05 11:39:47 myproject systemd[1]: Stopped uWSGI Emperor service.
Aug 05 11:39:47 myproject systemd[1]: Starting uWSGI Emperor service...
Aug 05 11:39:47 myproject systemd[14970]: uwsgi.service: Failed at step EXEC spawning /usr/local/bin/uwsgi: No such file or directory
如果我 运行 下面(不在 virtualenv 中)
python3 -c 'import django.core.wsgi'
我明白了
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'django'
但是如果我 运行 它在 virtualenv 中,我不会收到任何错误,这意味着错误与 uWSGI
.
有关
运行 python manage.py runserver
我的 manage.py
级别工作正常。
pip3 -V
给出 pip 19.2.1 from /home/user/.local/lib/python3.6/site-packages/pip (python 3.6)
和python3.6 -V
给出Python 3.6.9
我尝试用 sudo -H pip3 install uwsgi
重新安装 uWSGI,它似乎总是安装到 python 3.5 site-packages
。
如果我在 virtualenv 中 运行 pip3 install uwsgi
安装到
Uninstalling uWSGI-2.0.18:
Would remove:
/home/user/Env/myproject/bin/uwsgi
/home/user/Env/myproject/lib/python3.6/site-packages/uWSGI-2.0.18.dist-info/*
/home/user/Env/myproject/l
ib/python3.6/site-packages/uwsgidecorators.py
我的 .ini 文件
[uwsgi]
project = myproject
uid = user
base = /home/%(uid)
chdir = %(base)/%(project)/src/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
我的File: /etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown user:www-data /run/uwsgi'
ExecStart=/home/user/Env/myproject/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
我的项目显然需要 python3.6 到 运行 而我没有解决方案,任何人都可以提供任何建议吗?
如果您在系统上使用两个不同版本的 python(您的系统范围 python 似乎是 3.5.2),那么您应该 pip install uwsgi
inside 包含您将要使用的 python 版本的 virtualenv。
然后你应该通过直接使用它的路径来启动那个特定的 uwsgi,在你的情况下/home/user/Env/myproject/bin/uwsgi:
> /home/user/Env/myproject/bin/uwsgi --ini /path/to/file/uwsgi.ini
或
> /home/user/Env/myproject/bin/uwsgi --http :8080 --home /home/user/Env/myproject --chdir /home/user/myproject/src/myproject -w myproject.wsgi
我花了一天时间想弄明白。
我运行正在 Digital Ocean
与 Django
、Python3.6
、Nginx
、Ubuntu 16.04
和 uWSGI
.
必须通过 deadsnakesppa
安装 Python3.6
并且有一个 virtualenv
我用
mkvirtualenv --python=python3.6 myproject
我正在关注 this tutorial 我之前已经关注但是当我尝试 运行 下面的代码来测试应用程序服务器(不在 virtualenv 中)
uwsgi --http :8080 --home /home/user/Env/myproject --chdir /home/user/myproject/src/myproject -w myproject.wsgi
我得到这个回溯
*** Starting uWSGI 2.0.18 (64bit) on [Mon Aug 5 12:23:53 2019] ***
compiled with version: 5.4.0 20160609 on 05 August 2019 11:53:48
os: Linux-4.4.0-157-generic #185-Ubuntu SMP Tue Jul 23 09:17:01 UTC 2019
nodename: myproject
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/user/myproject/src/myproject
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3898
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8080 fd 4
spawned uWSGI http 1 (pid: 17338)
uwsgi socket 0 bound to TCP address 127.0.0.1:34660 (port auto-assigned) fd 3
Python version: 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x21aaf90
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./myproject/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named 'django'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 17337, cores: 1)
当我激活 virtualenv 时,我得到了同样的结果。
更多错误日志是
Aug 05 12:18:20 myproject uwsgi[16998]: --- no python application found, check your system...
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Main process exited, code=exited, status=203/EXEC
Aug 05 11:39:47 myproject systemd[1]: Failed to start uWSGI Emperor service.
Aug 05 11:39:47 wmyproject systemd[1]: uwsgi.service: Unit entered failed state.
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Failed with result 'exit-code'.
Aug 05 11:39:47 myproject systemd[1]: uwsgi.service: Service hold-off time over, scheduling restart.
Aug 05 11:39:47 myproject systemd[1]: Stopped uWSGI Emperor service.
Aug 05 11:39:47 myproject systemd[1]: Starting uWSGI Emperor service...
Aug 05 11:39:47 myproject systemd[14970]: uwsgi.service: Failed at step EXEC spawning /usr/local/bin/uwsgi: No such file or directory
如果我 运行 下面(不在 virtualenv 中)
python3 -c 'import django.core.wsgi'
我明白了
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'django'
但是如果我 运行 它在 virtualenv 中,我不会收到任何错误,这意味着错误与 uWSGI
.
运行 python manage.py runserver
我的 manage.py
级别工作正常。
pip3 -V
给出 pip 19.2.1 from /home/user/.local/lib/python3.6/site-packages/pip (python 3.6)
和python3.6 -V
给出Python 3.6.9
我尝试用 sudo -H pip3 install uwsgi
重新安装 uWSGI,它似乎总是安装到 python 3.5 site-packages
。
如果我在 virtualenv 中 运行 pip3 install uwsgi
安装到
Uninstalling uWSGI-2.0.18:
Would remove:
/home/user/Env/myproject/bin/uwsgi
/home/user/Env/myproject/lib/python3.6/site-packages/uWSGI-2.0.18.dist-info/*
/home/user/Env/myproject/l
ib/python3.6/site-packages/uwsgidecorators.py
我的 .ini 文件
[uwsgi]
project = myproject
uid = user
base = /home/%(uid)
chdir = %(base)/%(project)/src/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
我的File: /etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown user:www-data /run/uwsgi'
ExecStart=/home/user/Env/myproject/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
我的项目显然需要 python3.6 到 运行 而我没有解决方案,任何人都可以提供任何建议吗?
如果您在系统上使用两个不同版本的 python(您的系统范围 python 似乎是 3.5.2),那么您应该 pip install uwsgi
inside 包含您将要使用的 python 版本的 virtualenv。
然后你应该通过直接使用它的路径来启动那个特定的 uwsgi,在你的情况下/home/user/Env/myproject/bin/uwsgi:
> /home/user/Env/myproject/bin/uwsgi --ini /path/to/file/uwsgi.ini
或
> /home/user/Env/myproject/bin/uwsgi --http :8080 --home /home/user/Env/myproject --chdir /home/user/myproject/src/myproject -w myproject.wsgi