V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
superhan
V2EX  ›  Python

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

  •  
  •   superhan · 2017-07-14 08:51:27 +08:00 · 6568 次点击
    这是一个创建于 2450 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最开始试用的 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, Connecti onError, 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.
    第 1 条附言  ·  2017-07-14 14:26:54 +08:00
    uwsgi 版本 2.0.15 不行 换了 2.0.14 可以 非常感谢
    19 条回复    2017-07-14 14:26:45 +08:00
    NaVient
        1
    NaVient  
       2017-07-14 09:18:49 +08:00
    from celery import Celery 这个文件不要叫 celery.py   改成_celery.py
    superhan
        2
    superhan  
    OP
       2017-07-14 09:25:23 +08:00
    @NaVient 谢谢。改了 还是同样的报错。我在 mac 上使用 uwsgi 跑一直没问题。但是放到 centos 就是这个报错
    NaVient
        3
    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
        4
    superhan  
    OP
       2017-07-14 09:47:08 +08:00
    @NaVient 嗯 改了 还是同样的报错
    csdreamdong
        5
    csdreamdong  
       2017-07-14 09:52:33 +08:00
    ImportError,这种类型的错,挺好定位的呀。
    csdreamdong
        6
    csdreamdong  
       2017-07-14 09:53:11 +08:00
    检查包是否有安装,与开发环境的版本是否相同。以及上下文的环境是否相同。
    csdreamdong
        7
    csdreamdong  
       2017-07-14 10:04:24 +08:00
    还有就是 uwsgi 的 chdir 这个配置是否正确。
    cloverstd
        8
    cloverstd  
       2017-07-14 10:08:16 +08:00
    你需要 Docker
    superhan
        9
    superhan  
    OP
       2017-07-14 10:22:58 +08:00
    @csdreamdong 与我 mac 开发环境代码相同 uwsgi 版本相同 有检查办法吗 求赐教一个
    csdreamdong
        10
    csdreamdong  
       2017-07-14 10:47:54 +08:00
    @superhan 第三方的一些包安装方式都一样么?都是 pip 安装的么?以及 uwsgi 的 chdir 配置
    superhan
        11
    superhan  
    OP
       2017-07-14 11:01:36 +08:00
    @csdreamdong 是 pip 离线安装的,chdir 是对的 在我的 mac 上跑没问题
    superhan
        12
    superhan  
    OP
       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
        13
    csdreamdong  
       2017-07-14 11:14:39 +08:00
    from amqp import ChannelError, Connecti onError, ResourceError
    单独的交互式的 python shell 里。。执行 import 会报错么
    superhan
        14
    superhan  
    OP
       2017-07-14 11:29:33 +08:00
    @csdreamdong 这样是没问题的 实在不行重装机器 这次没用 venv
    superhan
        15
    superhan  
    OP
       2017-07-14 12:48:00 +08:00
    @csdreamdong 换了机器 装了 env 还是不行 ,我觉得我要崩溃了
    ptrees
        16
    ptrees  
       2017-07-14 13:12:38 +08:00
    python 或者 uwsgi 版本有没有问题?
    superhan
        17
    superhan  
    OP
       2017-07-14 13:38:27 +08:00
    @ptrees manager.py runserver 跑没有问题
    superhan
        18
    superhan  
    OP
       2017-07-14 14:26:36 +08:00
    @ptrees uwsgi 版本 2.0.15 不行 换了 2.0.14 可以 非常感谢
    superhan
        19
    superhan  
    OP
       2017-07-14 14:26:45 +08:00
    @csdreamdong uwsgi 版本 2.0.15 不行 换了 2.0.14 可以 非常感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2442 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:51 · PVG 23:51 · LAX 08:51 · JFK 11:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.