django 使用 uwsgi 启动问题, import 错误 好难啊,求大家指导

2017-07-14 08:51:27 +08:00
 superhan
最开始试用的 django rest 没有问题跑了一段时间。新加了 celery 模块部署到服务器一直报下面的错误。现在使用 runserver 启动也是没问题的,使用 uwsgi 启动就会报错。
from . import sasl
ImportError: cannot import name sasl



下面是启动报错信息。
uwsgi --ini mysite_uwsgi.ini
[uWSGI] getting INI configuration from mysite_uwsgi.ini
*** Starting uWSGI 2.0.15 (64bit) on [Fri Jul 14 08:48:30 2017] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-18) on 14 July 2017 08:26:28
os: Linux-2.6.32-696.1.1.el6.x86_64 #1 SMP Tue Apr 11 17:13:24 UTC 2017
nodename: jccs_no-pt-hc-vm1
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /usr/local/tutorial
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /usr/local/tutorial
your processes number limit is 39168
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 socket 0 bound to UNIX address /usr/local/tutorial/tutorial/mysite.sock fd 3
Python version: 2.7.13 (default, Mar 13 2017, 10:23:38) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xa2fc70
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 800448 bytes (781 KB) for 10 cores
*** Operational MODE: preforking ***
Traceback (most recent call last):
File "/usr/local/tutorial/tutorial/wsgi.py", line 21, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/tutorial/tutorial/__init__.py", line 5, in <module>
from .celery import app as celery_app
File "/usr/local/tutorial/tutorial/celery.py", line 3, in <module>
from celery import Celery
File "/usr/local/lib/python2.7/site-packages/celery/local.py", line 509, in __getattr__
module = __import__(self._object_origins[name], None, None, [name])
File "/usr/local/lib/python2.7/site-packages/celery/app/__init__.py", line 5, in <module>
from celery import _state
File "/usr/local/lib/python2.7/site-packages/celery/_state.py", line 15, in <module>
from celery.utils.threads import LocalStack
File "/usr/local/lib/python2.7/site-packages/celery/utils/__init__.py", line 10, in <module>
from .nodenames import worker_direct, nodename, nodesplit
File "/usr/local/lib/python2.7/site-packages/celery/utils/nodenames.py", line 7, in <module>
from kombu.entity import Exchange, Queue
File "/usr/local/lib/python2.7/site-packages/kombu/entity.py", line 6, in <module>
from .abstract import MaybeChannelBound, Object
File "/usr/local/lib/python2.7/site-packages/kombu/abstract.py", line 6, in <module>
from .connection import maybe_channel
File "/usr/local/lib/python2.7/site-packages/kombu/connection.py", line 15, in <module>
from kombu import exceptions
File "/usr/local/lib/python2.7/site-packages/kombu/exceptions.py", line 6, in <module>
from amqp import ChannelError, ConnectionError, ResourceError
File "/usr/local/lib/python2.7/site-packages/amqp/__init__.py", line 47, in <module>
from .connection import Connection # noqa
File "/usr/local/lib/python2.7/site-packages/amqp/connection.py", line 27, in <module>
from . import sasl
ImportError: cannot import name sasl
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 master process (pid: 14535)
spawned uWSGI worker 1 (pid: 14539, cores: 1)
spawned uWSGI worker 2 (pid: 14540, cores: 1)
spawned uWSGI worker 3 (pid: 14541, cores: 1)
spawned uWSGI worker 4 (pid: 14542, cores: 1)
spawned uWSGI worker 5 (pid: 14543, cores: 1)
spawned uWSGI worker 6 (pid: 14544, cores: 1)
spawned uWSGI worker 7 (pid: 14545, cores: 1)
spawned uWSGI worker 8 (pid: 14546, cores: 1)
spawned uWSGI worker 9 (pid: 14547, cores: 1)
spawned uWSGI worker 10 (pid: 14548, cores: 1)
^CSIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
worker 2 buried after 1 seconds
worker 3 buried after 1 seconds
worker 4 buried after 1 seconds
worker 5 buried after 1 seconds
worker 6 buried after 1 seconds
worker 7 buried after 1 seconds
worker 8 buried after 1 seconds
worker 9 buried after 1 seconds
worker 10 buried after 1 seconds
goodbye to uWSGI.
6605 次点击
所在节点    Python
19 条回复
NaVient
2017-07-14 09:18:49 +08:00
from celery import Celery 这个文件不要叫 celery.py   改成_celery.py
superhan
2017-07-14 09:25:23 +08:00
@NaVient 谢谢。改了 还是同样的报错。我在 mac 上使用 uwsgi 跑一直没问题。但是放到 centos 就是这个报错
NaVient
2017-07-14 09:42:43 +08:00
@superhan from .celery import app as celery_app  这一句也要改一下  from ._celery import app as celery_app
superhan
2017-07-14 09:47:08 +08:00
@NaVient 嗯 改了 还是同样的报错
csdreamdong
2017-07-14 09:52:33 +08:00
ImportError,这种类型的错,挺好定位的呀。
csdreamdong
2017-07-14 09:53:11 +08:00
检查包是否有安装,与开发环境的版本是否相同。以及上下文的环境是否相同。
csdreamdong
2017-07-14 10:04:24 +08:00
还有就是 uwsgi 的 chdir 这个配置是否正确。
cloverstd
2017-07-14 10:08:16 +08:00
你需要 Docker
superhan
2017-07-14 10:22:58 +08:00
@csdreamdong 与我 mac 开发环境代码相同 uwsgi 版本相同 有检查办法吗 求赐教一个
csdreamdong
2017-07-14 10:47:54 +08:00
@superhan 第三方的一些包安装方式都一样么?都是 pip 安装的么?以及 uwsgi 的 chdir 配置
superhan
2017-07-14 11:01:36 +08:00
@csdreamdong 是 pip 离线安装的,chdir 是对的 在我的 mac 上跑没问题
superhan
2017-07-14 11:02:55 +08:00
@csdreamdong ['/usr/local/tutorial', '.', '', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
csdreamdong
2017-07-14 11:14:39 +08:00
from amqp import ChannelError, Connecti onError, ResourceError
单独的交互式的 python shell 里。。执行 import 会报错么
superhan
2017-07-14 11:29:33 +08:00
@csdreamdong 这样是没问题的 实在不行重装机器 这次没用 venv
superhan
2017-07-14 12:48:00 +08:00
@csdreamdong 换了机器 装了 env 还是不行 ,我觉得我要崩溃了
ptrees
2017-07-14 13:12:38 +08:00
python 或者 uwsgi 版本有没有问题?
superhan
2017-07-14 13:38:27 +08:00
@ptrees manager.py runserver 跑没有问题
superhan
2017-07-14 14:26:36 +08:00
@ptrees uwsgi 版本 2.0.15 不行 换了 2.0.14 可以 非常感谢
superhan
2017-07-14 14:26:45 +08:00
@csdreamdong uwsgi 版本 2.0.15 不行 换了 2.0.14 可以 非常感谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/375223

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX