【问题标题】:ImportError: No module named site. Flask + uWSGI +virtualenvImportError:没有名为站点的模块。烧瓶 + uWSGI +virtualenv
【发布时间】:2015-01-15 03:27:06
【问题描述】:

我无法让我的烧瓶应用程序在运行 CentOS 6.5 的新服务器上运行。使用 uWSGI。 (我有一个类似的 CentOS 机器,它运行良好)

我在虚拟环境中安装了 uWSGI。从 virtualenv 调用 uwsgi 二进制文件时出现以下错误(在 stdout 中)

$ /path/to/venv/bin/uwsgi --emperor /etc/uwsgi/vassals

*** Starting uWSGI 2.0.8 (64bit) on [Mon Nov 17 21:18:13 2014] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-11) on 16 November 2014 22:19:09
os: Linux-2.6.32-431.1.2.0.1.el6.x86_64 #1 SMP Fri Dec 13 13:06:13 UTC 2013
nodename: boxname
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/username
detected binary path: /home/username/mydevelopment/venvs/ecodev_do/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 1024
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from ers_portal_uwsgi.ini
Mon Nov 17 21:18:14 2014 - [emperor] curse the uwsgi instance ers_portal_uwsgi.ini (pid: 22724)
Mon Nov 17 21:18:17 2014 - [emperor] removed uwsgi instance ers_portal_uwsgi.ini

uwsgi.log 文件显示:

*** Starting uWSGI 2.0.8 (64bit) on [Mon Nov 17 21:25:40 2014] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-11) on 16 November 2014 22:19:09
os: Linux-2.6.32-431.1.2.0.1.el6.x86_64 #1 SMP Fri Dec 13 13:06:13 UTC 2013
nodename: boxname
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /home/username/mydevelopment/venvs/ecodev_do/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/username/mydevelopment/git/ers_portal
your processes number limit is 1024
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 /home/username/mydevelopment/git/ers_portal/ers_portal_uwsgi.sock fd 3
Python version: 2.7.8 (default, Nov 12 2014, 23:36:57)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]
Set PythonHome to /home/username/mydevelopment/venvs/ecovapor_dev
ImportError: No module named site

然后,阅读他们描述的官方 uWSGI 文档a scenario,其中 uwsgi 安装在 venv 中,但之后必须在系统范围内安装。所以,我用 pip2.7 install uwsgi(在 /usr/local/bin/uwsgi 中创建了二进制文件)

我已经尝试了以下所有方法,但错误或输出没有变化(激活和未激活 venv)..

  1. $ /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals

  2. $ /home/username/mydevelopment/venvs/ecodev_do/bin/uwsgi --emperor /etc/uwsgi/vassals

  3. $ /home/username/mydevelopment/venvs/ecodev_do/bin/uwsgi --no-site --emperor /etc/uwsgi/vassals

  4. $ uwsgi --emperor /etc/uwsgi/vassals

  5. $ uwsgi --no-site --emperor /etc/uwsgi/vassals

  6. $ /path/to/venv/bin/uwsgi ~/mydevelopment/git/ers_portal/ers_portal_uwsgi.ini(.ini 文件在/etc/uwsgi/vassals 中符号链接)

这里是emperor.ini;

[uwsgi]
emperor = /etc/uwsgi/vassals
uid = username
gid = username
logto = /home/username/mydevelopment/git/ers_portal/logs/uwsgiEmperor.log

这里是ers_portal_uwsgi.ini

[uwsgi]
master = true
#user info
uid = username
gid = username

#application's base folder
base = /home/username/mydevelopment/git/ers_portal

#chdir to this folder when starting
chdir = /home/username/mydevelopment/git/ers_portal

#python module to import
app = run_web
module = %(app)

home = /home/username/mydevelopment/venvs/ecovapor_dev
pythonpath = %(base)

#socket file's location
socket = /home/username/mydevelopment/git/ers_portal/%n.sock

#permissions for the socket file
chmod-socket    = 666

#the variable that holds a flask application inside the module imported at line #6
#uwsgi varible only, does not relate to your flask application
callable = app

#location of log files
logto = /home/username/mydevelopment/git/ers_portal/logs/%n.log

【问题讨论】:

  • 我以前遇到过这个问题,对我来说,问题是 uwsgi 是从根 python 目录运行的,而不是我的 virtualenv。我不得不为我的运行脚本使用绝对目录。
  • @Celeo 你在哪里指定我不在的绝对目录?
  • 确保你的 virtualenv 是为 uWSGI 使用的相同版本构建的
  • @roberto 你介意澄清你的评论吗? virtualenv 与运行应用程序的虚拟环境相同,与我 pip 安装的 uwsgi 相同。原谅我,我不明白你的评论(建成?)

标签: python flask centos virtualenv uwsgi


【解决方案1】:

如果有人使用 python 3.x,使用 pip3 安装 uwsgi 为我解决了这个问题:

sudo pip3 install uwsgi

有问题的 virtualenv 和 uwsgi 必须使用相同的 python 版本。

如果您想在同一系统上使用多个 python 版本,您可以获取 uwsgi source 并按照此处的说明进行操作:http://projects.unbit.it/uwsgi/wiki/MultiPython

然后在 .ini 文件中添加“plugin=/path/to/plugin”

请注意,插件不适用于打包的 Ubuntu 版本(内置单体),但您需要直接编译源代码以获得完全模块化的二进制文件

【讨论】:

    【解决方案2】:

    这对我有帮助。 在终端中输入。

    unset PYTHONHOME
    unset PYTHONPATH
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 2014-01-30
      相关资源
      最近更新 更多