簡體   English   中英

ImportError:沒有名為站點的模塊。 Flask + uWSGI + virtualenv

[英]ImportError: No module named site. Flask + uWSGI +virtualenv

我無法使用uWSGI使燒瓶應用程序在運行CentOS 6.5的新服務器上運行。 (我有一個運行良好的類似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文檔,他們描述將uwsgi安裝在venv中的情況,但是之后必須在系統范圍內進行安裝。 所以,我用pip2.7 install uwsgi (在/usr/local/bin/uwsgi pip2.7 install 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 $ /path/to/venv/bin/uwsgi ~/mydevelopment/git/ers_portal/ers_portal_uwsgi.ini鏈接)

這是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

萬一有人使用python 3.x,用pip3安裝uwsgi可以為我解決這個問題:

sudo pip3 install uwsgi

有問題的virtualenv和uwsgi必須使用相同的python版本。

如果要在同一系統上使用多個python版本,則可以獲取uwsgi 源碼並按照此處的說明進行操作: http : //projects.unbit.it/uwsgi/wiki/MultiPython

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

請注意,插件不適用於打包的Ubuntu版本(單片構建),但是您需要直接編譯源代碼以獲取完全模塊化的二進制文件

這對我有幫助。 在您的終端中輸入。

unset PYTHONHOME
unset PYTHONPATH

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM