繁体   English   中英

导入错误:没有名为“django”的模块 uWSGI Django Nginx Ubuntu 16.04 Python3.6

[英]ImportError: No module named 'django' uWSGI Django Nginx Ubuntu 16.04 Python3.6

我花了一天时间试图弄清楚这一点。

我正在使用DjangoPython3.6NginxUbuntu 16.04uWSGIDigital Ocean上运行。

必须通过deadsnakesppa安装Python3.6并有一个我创建的virtualenv

mkvirtualenv --python=python3.6 myproject

我正在遵循我之前遵循的本教程,但是当我尝试运行以下代码来测试应用程序服务器时(不在 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

从我的manage.py级别运行python manage.py runserver工作正常。

pip3 -V pip 19.2.1 from /home/user/.local/lib/python3.6/site-packages/pip (python 3.6)给出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 重新安装 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),那么您应该包含要使用的 python 版本的 virtualenv 中pip install uwsgi

然后你应该直接使用它的路径来启动那个特定的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

暂无
暂无

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

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