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
luckyqiang
V2EX  ›  Python

uwsgi+nginx 部署 django 报错

  •  
  •   luckyqiang · 2018-03-12 20:47:54 +08:00 · 4429 次点击
    这是一个创建于 2208 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Fatal Python error: Py_Initialize: Unable to get the locale encoding ImportError: No module named 'encodings'

    查了好多资料都查不出问题 有人知道怎么弄吗

    12 条回复    2018-03-14 08:47:27 +08:00
    chaunceywe
        2
    chaunceywe  
       2018-03-12 23:32:59 +08:00 via Android
    sudo apt-get install python3-dev -y
    luckyqiang
        3
    luckyqiang  
    OP
       2018-03-13 08:33:25 +08:00
    @chaunceywe 试了还是不行 感觉是 py2 和 py3 的环境乱了 我 django 用的是 py3 把服务器 ubuntu 里也默认改为 py3 了 不知道哪里出了问题
    chaunceywe
        4
    chaunceywe  
       2018-03-13 09:30:21 +08:00 via Android
    @luckyqiang 只是没安装 python 依赖的问题,用 python 几安装几的
    luckyqiang
        5
    luckyqiang  
    OP
       2018-03-13 10:06:01 +08:00
    @chaunceywe python3-dev is already the newest version (3.5.1-3). 应该安装了吧
    luckyqiang
        6
    luckyqiang  
    OP
       2018-03-13 10:07:13 +08:00
    @chaunceywe (mysite_env) ubuntu@VM-0-8-ubuntu:~/myblog$ uwsgi --ini uwsgi.ini
    [uWSGI] getting INI configuration from uwsgi.ini
    *** Starting uWSGI 2.0.17 (64bit) on [Tue Mar 13 09:56:19 2018] ***
    compiled with version: 5.4.0 20160609 on 12 March 2018 08:17:28
    os: Linux-4.4.0-91-generic #114-Ubuntu SMP Tue Aug 8 11:56:56 UTC 2017
    nodename: VM-0-8-ubuntu
    machine: x86_64
    clock source: unix
    detected number of CPU cores: 1
    current working directory: /home/ubuntu/myblog
    detected binary path: /home/ubuntu/.local/bin/uwsgi
    !!! no internal routing support, rebuild with pcre support !!!
    chdir() to /home/ubuntu/myblog/mysite_env/mysite
    your processes number limit is 3306
    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 :8001 fd 3
    Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
    Set PythonHome to /home/ubuntu/myblog/mysite_env
    Fatal Python error: Py_Initialize: Unable to get the locale encoding
    ImportError: No module named 'encodings'

    Current thread 0x00007fd0c8473700 (most recent call first):
    Aborted (core dumped)
    运行就是报这样的错误
    luckyqiang
        7
    luckyqiang  
    OP
       2018-03-13 10:09:11 +08:00
    @Yourshell (mysite_env) ubuntu@VM-0-8-ubuntu:~/myblog$ python
    Python 3.5.2 (default, Nov 23 2017, 16:37:01)
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    我的 python 应该没有问题
    xvx
        8
    xvx  
       2018-03-13 10:19:02 +08:00 via iPhone
    这是我用 Django/Flask 开发的个人博客,uwsgi+nginx 我是这么部署的,没有出现你这种报错,你可以将虚拟环境卸载了重新创建一个,按照我的方法试试?
    我的 Github 里面还有相应的配置文件,都开源出来了,可以参考下。

    http://www.vua.sh/#7974a888-0a55-488b-b48b-23dcdd6826ac
    Kirikora
        9
    Kirikora  
       2018-03-13 10:23:05 +08:00 via Android
    @luckyqiang uwsgi 也装在虚拟环境里,然后调用虚拟环境里的 uwsgi 试试?
    luckyqiang
        11
    luckyqiang  
    OP
       2018-03-13 20:24:03 +08:00
    @xvx 我是把本地的虚拟环境也打包上去了 估计就是那个问题 本地是 python3.6 服务器好像是 3.5
    xvx
        12
    xvx  
       2018-03-14 08:47:27 +08:00
    @luckyqiang 不建议这么干。一般虚拟环境都是在服务器上面部署时创建的,本地环境跟服务器环境有些版本、依赖不一致,你最好是在服务器上面新建一个虚拟环境。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   996 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:03 · PVG 04:03 · LAX 13:03 · JFK 16:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.