经过各种坑之后centos+ uwsgi + nginx +django 终于配好了

https://pypi.python.org/pypi/setuptools#downloads

https://www.python.org/ftp/python/

开机 加入 uwsgi nginx 自启动

echo "/etc/init.d/nginx restart" >>/etc/rc.local 

echo "/usr/bin/setsid /data/soft_ware/uwsgi-1.9.6/uwsgi /data/soft_ware/s10day11/demo.ini " >>/etc/rc.local 

setsid 是后台挂起不受hungup 信号的影响。 进程号为1 与init相同

一 centos python是2.6 版本所以我们需要 装python2.7.9  请看之前的博客

查看python的版本

[plain] view plaincopy
 
  1. #python  -V    
  2. Python 2.6.6  


1.下载Python-2.7.3

[plain] view plaincopy
 
  1. #wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2  

附带 3.5.1 https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz
2.解压

[plain] view plaincopy
 
  1. #tar -jxvf Python-2.7.3.tar.bz2  


3.更改工作目录

[plain] view plaincopy
 
  1. #cd Python-2.7.3  


4.安装

 yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
[plain] view plaincopy
 
  1. #./configure  
  2. #make all             
  3. #make install  
  4. #make clean  
  5. #make distclean  


5.查看版本信息

[plain] view plaincopy
 
  1. #/usr/local/bin/python2.7 -V  


6.建立软连接,使系统默认的 python指向 python2.7

[plain] view plaincopy
 
  1. #mv /usr/bin/python /usr/bin/python2.6.6  
  2. #ln -s /usr/local/bin/python2.7 /usr/bin/python  


7.重新检验Python 版本

[plain] view plaincopy
 
  1. #python -V  


8解决系统 Python 软链接指向 Python2.7 版本后,因为yum是不兼容 Python 2.7的,所以yum不能正常工作,我们需要指定 yum 的Python版本

[plain] view plaincopy
 
  1. #vi /usr/bin/yum  

将文件头部的
#!/usr/bin/python


改成
#!/usr/bin/python2.6.6

http://www.zhangchun.org/the-centos6-3-upgrade-python-to-2-7-3-

这篇教程就到这里了,但是不久就突然发现输入法图标不见了,然后打字没有候选框!iBus 崩了!再次进行搜索,又是版本问题抓狂 iBus也是不支持Python2.7的啊!

于是。。。

以前在使用Python的时候,都是使用root用户安装好的全局python,现在,因为root用户安装的Python版本太低,同时自己没有root权限去对全局Python升级,所以要在非root用户下安装自己指定的Python。因此,就重新整理了一份如何在Linux环境下使用非root用户安装python及其相关的库,以备不时之需。

安装python

python版本库https://www.python.org/ftp/python/,此处我选择2.7.5版本的,在安装python的时候,使用--prefix指定安装路径即可,命令如下:

wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
tar -xzf Python-2.7.5.tgz
cd Python-2.7.5
mkdir -p /home/liudiwei/software/python27 
./configure --prefix="/home/liudiwei/software/python27"
make
make install

[liujianzuo@sy01-db3 pip-8.1.1]$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=/home/liujianzuo/bin/python/bin:$PATH:$HOME/bin

export PATH

[liujianzuo@sy01-db3 ~]$ . .bash_profile

[liujianzuo@sy01-db3 ~]$ which python
~/bin/python/bin/python

安装setuptools

setuptools主要是为安装pip做准备的,下面是从下载到安装的全部命令,使用上面安装的指定路径的python/home/liudiwei/software/python27/bin/python进行安装:

https://pypi.python.org/pypi/setuptools页面最下面的有它的安装链接

cd /home/work/prober/src/lib/thirdparty
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-12.0.3.tar.gz#md5=f07e4b0f4c1c9368fcd980d888b29a65 
tar xvf setuptools-12.0.3.tar.gz
cd setuptools-12.0.3
python setup.py install
cd ..
wget --no-check-certificate https://pypi.python.org/packages/41/27/9a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-8.1.1.tar.gz#md5=6b86f11841e89c8241d689956ba99ed7
tar -xzf pip-8.1.1.tar.gz
cd pip-8.1.1
python setup.py install
cd ..
# 升级pip
python -m pip install --upgrade pip
 

安装pip

使用pip来安装python相关库,方便简单,此处将python setup.py install的python换成自己安装的指定路径下的python/home/liudiwei/software/python27/bin/python setup.py install.

wget --no-check-certificate https://pypi.python.org/packages/41/27/9a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-8.1.1.tar.gz#md5=6b86f11841e89c8241d689956ba99ed7
tar -xzf pip-8.1.1.tar.gz
cd pip-8.1.1
python setup.py install

安装相关库

进入python安装目录的bin路径下,安装下面相关库,经测试,下列库均可安装。

  • simplejson
  • redis
  • numpy
  • scipy
  • sklearn

安装命令:

cd /home/liudiwei/software/python27/bin/
./pip install simplejson
./pip install redis
./pip install numpy
./pip install scipy
./pip install sklearn

关于matplotlib的安装,因为系统有些依赖包没有安装而导致matplotlib安装失败,如libpng, freetype等,待后续安装完成后,再来完善。

 
 

9.配置iBus

分别用 vi 打开下面两个文件,找到 exec python 那一行,把exec python 改为 exec python2.6 保存,退出。iBus在重启后就恢复正常了!是不是很开心?

[plain] view plaincopy
 
  1. #vi /usr/bin/ibus-setup  
[plain] view plaincopy
 
    1. #vi/usr/libexec/ibus-ui-gtk  

二 、centos 安装django  python支持的mysql模块

yum -y install mysql-devel

[root@ayibang-server ~]# yum install -y MySQL-python

安装uwsgi  尽量别装 2版本 会报错。 当然用如下方法装2 版本 指定python版本安装uwsgi也行。 待测。

重装 uwsgi1.9版本 指定python版本 python2.7

[root@ayibang-server soft_ware]# tar zxf uwsgi-1.9.6.tar.gz 
[root@ayibang-server soft_ware]# cd uwsgi-1.9.6
[root@ayibang-server uwsgi-1.9.6]# python
python python-config python2 python2-config python2.7 python2.7-config
[root@ayibang-server uwsgi-1.9.6]# python2.7 uwsgiconfig.py --build

装django

[root@ayibang-server soft_ware]# tar zxvf Django-1.8.4.tar.gz 

                  cd Django-1.8.4 之后 如果执行 安装 就是python版本问题

[root@ayibang-server Django-1.8.4]# python setup.py install
Traceback (most recent call last):
File "setup.py", line 32, in <module>
version = __import__('django').get_version()
File "/data/soft_ware/Django-1.8.4/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/data/soft_ware/Django-1.8.4/django/utils/version.py", line 7, in <module>
from django.utils.lru_cache import lru_cache
File "/data/soft_ware/Django-1.8.4/django/utils/lru_cache.py", line 28
fasttypes = {int, str, frozenset, type(None)},
^
SyntaxError: invalid syntax

解决

[root@ayibang-server soft_ware]# wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz

接下来就是 第一步的操作; 安装2.7版本python

四 报错 没装settools

[root@ayibang-server Django-1.8.4]# python setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import find_packages, setup
ImportError: No module named setuptools

1. 下载setuptools及pip的源码包
	setuptools与pip都是python的模块
	setuptools源码包: https://pypi.python.org/pypi/setuptools
	pip源码包: https://pypi.python.org/pypi/pip#downloads
2. 安装setuptools与pip
目前下载的版本是setuptools-12.0.5.tar.gz与pip-6.0.6.tar.gz

先安装setuptools, 进行setuptools的源码根目录下, 执行以下命令进行setuptools模块的安装:

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. # python setup.py install  
安装完setuptools后, 接着安装pip, 进入pip的源码包根目录下, 执行以下命令进行安装:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. # python setup.py build  
  2. # python setup.py install  
安装完pip后. 看看pip都安装在哪里. 执行以下命令:

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. # whereis pip  
然后再执行 # pip  命令并回车, 如果无法用pip命令, 则可通过创建pip软链接, 执行以下命令:


重装django 检测

[root@ayibang-server Django-1.8.7]# python
Python 2.7.9 (default, Dec 3 2015, 01:04:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>


五 5.关联django到nginx

服务器已经在跑PHP站点,现在新生成一个虚拟服务器

[root@ayibang-server ~]# cat /etc/nginx/conf.d/django.conf
server {
listen 8000;
server_name 192.168.1.200;
location / {
include uwsgi_params;
uwsgi_pass 0.0.0.0:9000;
}
}

完成后重启下nginx服务
$ sudo /etc/init.d/nginx restart

六 配置 uwsgi 启动文件   这里有个错 ,网上文章有错误 网上的文件写的可能是早期的 版本。 

1 py文件启动

[root@ayibang-server ~]# cd /data/soft_ware/mysite/  #进到项目目录
[root@ayibang-server mysite]# ls
app01 db.sqlite3 demo.ini demo.py demo.pyc manage.py mysite

编辑一个py文件
[root@ayibang-server mysite]# cat demo.py
#!/usr/bin/env python
#coding:utf-8
import os
from django.core.wsgi import get_wsgi_application   #网上的大都导入的其他模块 这个版本1.9 uwsgi 1.8 django 可能就不支持了
os.environ['DJANGO_SETTINGS_MODULE']='mysite.settings' #项目名 mysite 记得改 ; setting 
application = get_wsgi_application()

启动 uwsgi  如下端口 对应 你的nginx的pass 端口   记住应用 你自己安装的 uwsg 看前面的第2三4补

[root@ayibang-server mysite]# /data/soft_ware/uwsgi-1.9.6/uwsgi -s 0.0.0.0:9000 -w demo

2  ini 文件启动

[root@ayibang-server ~]# cd /data/soft_ware/mysite/  #进到项目目录
[root@ayibang-server mysite]# ls 

[uwsgi]
socket = 0.0.0.0:9000
processes = 3  #进程数 
chdir = /data/soft_ware/mysite/ #项目名 mysite 记得改
pythonpath = /usr/local/bin/python
env = DJANGO_SETTINGS_MODULE=mysite.settings   #项目名 mysite 记得改 ; setting 
module = django.core.wsgi:get_wsgi_application()

ini 文件 启动方式

[root@ayibang-server s10day11]# /data/soft_ware/uwsgi-1.9.6/uwsgi demo.ini 

对比 我的 另一个项目 的不同

[root@ayibang-server ~]# cd /data/soft_ware/s10day11/
[root@ayibang-server s10day11]# ls
app01 app03 app04 db.sqlite3 demo.ini demo.py demo.pyc manage.py s10day11 statics templates test
[root@ayibang-server s10day11]# cat demo.py
#!/usr/bin/env python
#coding:utf-8
import os
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE']='s10day11.settings'
application = get_wsgi_application()
[root@ayibang-server s10day11]# cat demo.ini
[uwsgi]
socket = 0.0.0.0:9000
processes = 9
chdir = /data/soft_ware/s10day11/
pythonpath = /usr/local/bin/python
env = DJANGO_SETTINGS_MODULE=s10day11.settings
module = django.core.wsgi:get_wsgi_application()

[root@ayibang-server s10day11]# /data/soft_ware/uwsgi-1.9.6/uwsgi demo.ini
[uWSGI] getting INI configuration from demo.ini
*** Starting uWSGI 1.9.6 (64bit) on [Thu Dec 3 15:02:25 2015] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-4) on 03 December 2015 12:59:57
os: Linux-2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013
nodename: ayibang-server
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /data/soft_ware/s10day11
detected binary path: /data/soft_ware/uwsgi-1.9.6/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 30853
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to TCP address 0.0.0.0:9000 fd 3
Python version: 2.7.9 (default, Dec 3 2015, 01:04:49) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xd129b0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 654264 bytes (638 KB) for 9 cores
*** Operational MODE: preforking ***
added /usr/local/bin/python to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xd129b0 pid: 23478 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (pid: 23478, cores: 1)
spawned uWSGI worker 2 (pid: 23485, cores: 1)
spawned uWSGI worker 3 (pid: 23486, cores: 1)
spawned uWSGI worker 4 (pid: 23487, cores: 1)
spawned uWSGI worker 5 (pid: 23488, cores: 1)
spawned uWSGI worker 6 (pid: 23489, cores: 1)
spawned uWSGI worker 7 (pid: 23490, cores: 1)
spawned uWSGI worker 8 (pid: 23491, cores: 1)
spawned uWSGI worker 9 (pid: 23492, cores: 1)

3 xml 文件启动方式

如安装了libxml2,也可用如下方法处理:
在app目录创建个django.xml文件
[root@ayibang-server s10day11]# sudo vi django.xml
内容如下:

 127.0.0.1:9090
2
 /var/www/erp/erp
 ..
 DJANGO_SETTINGS_MODULE=mysite.settings
 django.core.wsgi:get_wsgi_application()


启动方式:
[root@ayibang-server s10day11]# uwsgi -x django.xml 

FAQ 总结

报错1  python版本不一致

[root@ayibang-server s10day11]# uwsgi -s 0.0.0.0:9999 -w demo
*** Starting uWSGI 2.0.6 (64bit) on [Thu Dec 3 12:29:00 2015] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-4) on 03 December 2015 00:55:54
os: Linux-2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013
nodename: ayibang-server
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /data/soft_ware/s10day11
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 30853
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 TCP address 0.0.0.0:9999 fd 3
Python version: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1a33780
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72768 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./demo.py", line 2, in <module>
import django.core.handlers.wsgi
ImportError: No module named django.core.handlers.wsgi
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 worker 1 (and the only) (pid: 26436, cores: 1)

开始 解决报错1  python 版本不一致

先pip uninstall uwsgi,然后yum install -y pcre pcre-devel pcre-static

安装pip

[root@ayibang-server soft_ware]# tar zxf pip-6.0.6.tar.gz
[root@ayibang-server soft_ware]# cd pip-
-bash: cd: pip-: No such file or directory
[root@ayibang-server soft_ware]# cd pip-6.0.6
[root@ayibang-server pip-6.0.6]# python setup.py build

[root@ayibang-server pip-6.0.6]# python setup.py install

创建项目 app

[root@ayibang-server soft_ware]# python /usr/local/bin/django-admin.py startproject mysite
[root@ayibang-server soft_ware]# python manage.py startapp app01

原来是 uwsgi是识别的 python2.6 而2.6 对django1.8不支持太好

[root@ayibang-server uwsgi-2.0.6]# ls /usr/bin/python*
/usr/bin/python /usr/bin/python2 /usr/bin/python2.6-config
/usr/bin/python-config /usr/bin/python2.6 /usr/bin/python2.6.6
[root@ayibang-server uwsgi-2.0.6]# vim /usr/bin/python-config
[root@ayibang-server uwsgi-2.0.6]# ls /usr/local/bin/python*
/usr/local/bin/python /usr/local/bin/python2 /usr/local/bin/python2.7
/usr/local/bin/python-config /usr/local/bin/python2-config /usr/local/bin/python2.7-config

重装 uwsgi1.9版本 指定python版本 python2.7

[root@ayibang-server soft_ware]# tar zxf uwsgi-1.9.6.tar.gz
[root@ayibang-server soft_ware]# cd uwsgi-1.9.6
[root@ayibang-server uwsgi-1.9.6]# python
python python-config python2 python2-config python2.7 python2.7-config
[root@ayibang-server uwsgi-1.9.6]# python2.7 uwsgiconfig.py --build

执行1.9版本报错 缺少lib   解决yum libyaml

[root@ayibang-server uwsgi-1.9.6]# ./uwsgi --version
./uwsgi: error while loading shared libraries: libyaml-0.so.2: cannot open shared object file: No such file or directory

[root@ayibang-server uwsgi-1.9.6]# yum install libyaml

[root@ayibang-server uwsgi-1.9.6]# which uwsgi
/usr/sbin/uwsgi
[root@ayibang-server uwsgi-1.9.6]# uwsgi --version
2.0.6

重新启动 

[root@ayibang-server mysite]# /data/soft_ware/uwsgi-1.9.6/uwsgi -s 127.0.0.1:9000 -w demo
*** Starting uWSGI 1.9.6 (64bit) on [Thu Dec 3 13:05:55 2015] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-4) on 03 December 2015 12:59:57
os: Linux-2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013
nodename: ayibang-server
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /data/soft_ware/mysite
detected binary path: /data/soft_ware/uwsgi-1.9.6/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 30853
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to TCP address 127.0.0.1:9000 fd 3
Python version: 2.7.9 (default, Dec 3 2015, 01:04:49) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x2844750
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72696 bytes (70 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x2844750 pid: 1772 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 1772, cores: 1)

报错2 解决

http://blog.163.com/rihui_7/blog/static/21228514320151353149688/ 

uwsgi+django报错django.core.exceptions.AppRegistryNotReady

uwsgi+django报错django.core.exceptions.AppRegistryNotReady

来源:http://www.aaini.com/

File “/usr/lib/python2.7/site-packages/django/core/handlers/wsgi.py”, line 187, in __call__
response = self.get_response(request)
File “/usr/lib/python2.7/site-packages/django/core/handlers/base.py”, line 199, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File “/usr/lib/python2.7/site-packages/django/core/handlers/base.py”, line 236, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File “/usr/lib/python2.7/site-packages/django/views/debug.py”, line 91, in technical_500_response
html = reporter.get_traceback_html()
File “/usr/lib/python2.7/site-packages/django/views/debug.py”, line 350, in get_traceback_html
return t.render(c)
File “/usr/lib/python2.7/site-packages/django/template/base.py”, line 148, in render
return self._render(context)
File “/usr/lib/python2.7/site-packages/django/template/base.py”, line 142, in _render
return self.nodelist.render(context)
File “/usr/lib/python2.7/site-packages/django/template/base.py”, line 844, in render
bit = self.render_node(node, context)
File “/usr/lib/python2.7/site-packages/django/template/debug.py”, line 80, in render_node
return node.render(context)
File “/usr/lib/python2.7/site-packages/django/template/debug.py”, line 90, in render
output = self.filter_expression.resolve(context)
File “/usr/lib/python2.7/site-packages/django/template/base.py”, line 624, in resolve
new_obj = func(obj, *arg_vals)
File “/usr/lib/python2.7/site-packages/django/template/defaultfilters.py”, line 769, in date
return format(value, arg)
File “/usr/lib/python2.7/site-packages/django/utils/dateformat.py”, line 343, in format
return df.format(format_string)
File “/usr/lib/python2.7/site-packages/django/utils/dateformat.py”, line 35, in format
pieces.append(force_text(getattr(self, piece)()))
File “/usr/lib/python2.7/site-packages/django/utils/dateformat.py”, line 268, in r
return self.format(‘D, j M Y H:i:s O’)
File “/usr/lib/python2.7/site-packages/django/utils/dateformat.py”, line 35, in format
pieces.append(force_text(getattr(self, piece)()))
File “/usr/lib/python2.7/site-packages/django/utils/encoding.py”, line 85, in force_text
s = six.text_type(s)
File “/usr/lib/python2.7/site-packages/django/utils/functional.py”, line 144, in __text_cast
return func(*self.__args, **self.__kw)
File “/usr/lib/python2.7/site-packages/django/utils/translation/__init__.py”, line 83, in ugettext
return _trans.ugettext(message)
File “/usr/lib/python2.7/site-packages/django/utils/translation/trans_real.py”, line 325, in ugettext
return do_translate(message, ‘ugettext’)
File “/usr/lib/python2.7/site-packages/django/utils/translation/trans_real.py”, line 306, in do_translate
_default = translation(settings.LANGUAGE_CODE)
File “/usr/lib/python2.7/site-packages/django/utils/translation/trans_real.py”, line 209, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File “/usr/lib/python2.7/site-packages/django/utils/translation/trans_real.py”, line 189, in _fetch
“The translation infrastructure cannot be initialized before the ”
django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don’t make non-lazy gettext calls at import time.

参照网上用uwsgi+nginx配置python环境时,报了这么个错,google发现是WSGI application的问题,好象是因为django升级,配置有所变化。

原来:

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

改成:

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

重启一下uwsgi。

网上找来的解决办法,希望有帮助。

后补:也可能是python版本和django版本不兼容问题,重新安装django并选定安装的版本就可以了

原来的 是如下 方式写的 不过我的改成上面 黄色部分  如下是老版本的 调用方法

配置并运行一个简单的python页面

$ cd /var/www/mysite
/var/www/mysite$ sudo vi demo.py
输入如下代码:
import  os
import  django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE']='mysite.settings'
application=django.core.handlers.wsgi.WSGIHandler()

/var/www/mysite$ uwsgi -s 127.0.0.1:9090 -w demo 

如安装了libxml2,也可用如下方法处理:
在app目录创建个django.xml文件
/var/www/mysite$ sudo vi django.xml
内容如下:

 127.0.0.1:9090
2
 /var/www/erp/erp
 ..
 DJANGO_SETTINGS_MODULE=mysite.settings
 django.core.handlers.wsgi:WSGIHandler()


启动方式:
/var/www/mysite$ uwsgi -x django.xml 

另一种配置方式,用于没有安装libxml2:
ini配置文件
/var/www/mysite$ sudo vi django.ini
[uwsgi]
socket = 127.0.0.1:9090
processes = 2
chdir = /var/www/mysite/mysite/
pythonpath = ..
env = DJANGO_SETTINGS_MODULE=mysite.settings
module = django.core.handlers.wsgi:WSGIHandler()

启动方式:
/var/www/mysite$ uwsgi django.ini 

服务成功启动后访问 http://127.0.0.1:8000,如能看到欢迎信息,就说明运行环境配置好了。更多的设置可以看下The_Django_Book
千里之行,始于足下。慢慢设计你的website吧...

原文地址:https://www.cnblogs.com/liujianzuo888/p/5016228.html