gpt4 book ai didi

python - Django,VirtualEnv,Ubuntu,uwsgi/gunicorn : Unable to locate all python/django modules

转载 作者:行者123 更新时间:2023-12-04 18:53:10 25 4
gpt4 key购买 nike

我正在尝试设置 uWSGI 来为我的 django 应用程序提供服务,但我遇到了路径问题,或者至少我认为这是一个路径问题。症状是当我向应用程序发出 curl 请求时,我得到的回溯表明找不到基本的 python/django 模块。前任:

File "/opt/example/venvs/example/lib/python2.7/site-packages/django/test/_doctest.py", line 104, in <module> import unittest, difflib, pdb, tempfile
File "/usr/lib/python2.7/pdb.py", line 59, in <module>
class Pdb(bdb.Bdb, cmd.Cmd): AttributeError: 'module' object has no attribute 'Cmd'

我查看了其他与 SO 相关的问题,但似乎都不是我的问题。

这是我的设置:
  • django==1.5.1
  • uwsgi==1.9.15(从 pip 安装)
  • python 是 2.7
  • Ubuntu 12.04 LTS
  • nginx = 0.8.54(但我不认为这是相关的,因为我还没有将 uwsgi 连接到 nginx)

  • 我在一个 vagrant 创建的 virtualbox 中运行,由 chef 和 fab 完成所有典型的配置。

    这是我 ssh 进入机器后的虚拟机路径:
    PATH="/opt/example/venvs/example/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant_ruby/bin"

    这是 .wsgi 文件(相当标准,除了我为调试添加的打印路径):
    import os
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

    import sys
    print sys.path

    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()

    这是 uwsgi ini 文件(注意我必须添加的所有各种 pythonpath):
    [uwsgi]
    #socket=/tmp/hs.com.sock
    virtualenv=/opt/example/venv
    chdir=/opt/example/apps/example/src
    module=example.wsgi:application
    master=true
    workers=8
    pidfile=/opt/example/apps/example/src/example/uwsgi-master.pid
    max-requests=5000
    #plugins=python
    enable-threads=true
    processes=2
    no-site=true
    http=:8003
    #env=DJANGO_SETTINGS_MODULE=example.settings
    pythonpath=..
    pythonpath=/vagrant/src
    pythonpath=/opt/example/apps/example/src/example
    pythonpath=/opt/example/venvs/example/lib/python2.7
    pythonpath=/opt/example/venvs/example/lib/python2.7/plat-linux2
    pythonpath=/opt/example/venvs/example/lib/python2.7/lib-tk
    pythonpath=/opt/example/venvs/example/lib/python2.7/lib-old
    pythonpath=/opt/example/venvs/example/lib/python2.7/lib-dynload
    pythonpath=/opt/example/venvs/example/lib/python2.7/distutils
    #pythonpath=/opt/example/venvs/example/lib/python2.7/encodings
    #pythonpath=/opt/example/venvs/example/lib/python2.7/config
    pythonpath=/usr/lib/python2.7/
    pythonpath=/usr/lib/python2.7/lib-dynload/
    pythonpath=/usr/lib/python2.7/distutils/
    pythonpath=/usr/lib/python2.7/plat-linux2/
    pythonpath=/usr/lib/python2.7/lib-tk/
    #pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/
    #pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/
    pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management
    #pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/commands
    pythonpath=/opt/example/venvs/example/local/lib/python2.7/site-packages
    pythonpath=/opt/example/venvs/example/lib/python2.7
    pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages
    pythonpath=/vagrant/src/example

    里面有这么多 pythonpaths 的原因是应用程序无法找到非常基本的模块,所以我不断添加路径来解决它。这适用于几个错误,但是 1)我找不到上面的 Cmd attributerror 的正确路径和 2)添加这些单独的路径中的每一个都感觉不对。

    uwsgi 输出到 'uwsgi --ini inifile'
    [uWSGI] getting INI configuration from xxx
    *** Starting uWSGI 1.9.15 (32bit) on [Fri Sep 13 18:12:44 2013] ***
    compiled with version: 4.6.3 on 13 September 2013 06:46:44
    os: Linux-3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012
    nodename: xxx
    machine: i686
    clock source: unix
    detected number of CPU cores: 1
    current working directory: /vagrant/src
    writing pidfile to /opt/example/apps/example/src/example/uwsgi-master.pid
    detected binary path: /opt/example/venvs/example/bin/uwsgi
    your processes number limit is 1824
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    uWSGI http bound on localhost:8003 fd 4
    uwsgi socket 0 bound to TCP address 127.0.0.1:34622 (port auto-assigned) fd 3
    Python version: 2.7.3 (default, Apr 10 2013, 06:03:17) [GCC 4.6.3]
    Set PythonHome to /opt/example/venv
    Python main interpreter initialized at 0xa044e58
    python threads support enabled
    your server socket listen backlog is limited to 100 connections
    your mercy for graceful operations on workers is 60 seconds
    mapped 192012 bytes (187 KB) for 2 cores
    *** Operational MODE: preforking ***
    added ../ to pythonpath.
    added /vagrant/src/ to pythonpath.
    added /opt/example/apps/example/src/example/ to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/ to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/plat-linux2 to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/lib-tk to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/lib-old to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/lib-dynload/ to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/distutils/ to pythonpath.
    added /usr/lib/python2.7/ to pythonpath.
    added /usr/lib/python2.7/lib-dynload/ to pythonpath.
    added /usr/lib/python2.7/distutils/ to pythonpath.
    added /usr/lib/python2.7/plat-linux2/ to pythonpath.
    added /usr/lib/python2.7/lib-tk/ to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/ to pythonpath.
    added /opt/example/venvs/example/local/lib/python2.7/site-packages/ to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/ to pythonpath.
    added /opt/example/venvs/example/lib/python2.7/site-packages/ to pythonpath.
    added /vagrant/src/example/ to pythonpath.
    ['/vagrant/src/example/', '/opt/example/venvs/example/lib/python2.7/site-packages/', '/opt/example/venvs/example/lib/python2.7/', '/opt/example/venvs/example/local/lib/python2.7/site-packages/', '/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/', '/usr/lib/python2.7/lib-tk/', '/usr/lib/python2.7/plat-linux2/', '/usr/lib/python2.7/distutils/', '/usr/lib/python2.7/lib-dynload/', '/usr/lib/python2.7/', '/opt/example/venvs/example/lib/python2.7/distutils/', '/opt/example/venvs/example/lib/python2.7/lib-dynload/', '/opt/example/venvs/example/lib/python2.7/lib-old', '/opt/example/venvs/example/lib/python2.7/lib-tk', '/opt/example/venvs/example/lib/python2.7/plat-linux2', '/opt/example/venvs/example/lib/python2.7/', '/opt/example/apps/example/src/example/', '/vagrant/src/', '../', '.', '', '/opt/example/venv/lib/python2.7/', '/opt/example/venv/lib/python2.7/plat-linux2', '/opt/example/venv/lib/python2.7/lib-tk', '/opt/example/venv/lib/python2.7/lib-old', '/opt/example/venv/lib/python2.7/lib-dynload', '/vagrant/src/example']
    WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xa044e58 pid: 2911 (default app)
    *** uWSGI is running in multiple interpreter mode ***
    spawned uWSGI master process (pid: 2911)
    spawned uWSGI worker 1 (pid: 2912, cores: 1)
    spawned uWSGI worker 2 (pid: 2913, cores: 1)
    spawned uWSGI http 1 (pid: 2914)

    从另一个终端我运行 curl -v localhost:8003 并得到我在上面发布的“AttributeError ...”。 curl 输出为:
    curl: (52) Empty reply from server
    * Closing connection #0

    这是我尝试过的:
  • 使用最新的 uWSGI 版本 1.9.15 和 LTS 版本 1.4.x
  • 在 virtualenv 内部和外部安装 uWSGI
  • django 的 runserver 可以很好地为我的应用程序提供服务,并且我可以看到由于 wsgi 文件中的 debug print sys.path 语句而打印出来的路径,它只是我在 wsgi.ini 文件中的路径的一个子集
  • 还从 wsgi.py 文件中打印出 runserver 和 uwsgi 环境中的环境变量,我没有看到任何重要的不同
  • uwsgi 能够毫无问题地提供基本的 test.py 应用程序文件,所以我相信这消除了任何安装/设置问题
  • 尝试使用 sudo
  • 运行 uwsgi

    我还尝试了一个基本的 django 应用程序(直接从 startproject 创建),这个也失败了,具有相同的属性错误,并且需要相同的 pythonpaths 列表。

    我一定缺少一些简单的设置或配置......?如果需要更多信息,请告诉我。

    Edit1:这看起来不是特定于 uWSGI,而是与 virtualenv 设置和路径更相关。我安装了 gunicorn 并得到了完全相同的结果。

    最佳答案

    我认为您的 uwsgi.ini 文件缺少一个“s”

    virtualenv=/opt/example/venv

    关于python - Django,VirtualEnv,Ubuntu,uwsgi/gunicorn : Unable to locate all python/django modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18794248/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com