uwsgi+nginx 部署 django 报错

2018-03-12 20:47:54 +08:00
 luckyqiang

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

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

4461 次点击
所在节点    Python
12 条回复
Yourshell
2018-03-12 22:15:20 +08:00
chaunceywe
2018-03-12 23:32:59 +08:00
sudo apt-get install python3-dev -y
luckyqiang
2018-03-13 08:33:25 +08:00
@chaunceywe 试了还是不行 感觉是 py2 和 py3 的环境乱了 我 django 用的是 py3 把服务器 ubuntu 里也默认改为 py3 了 不知道哪里出了问题
chaunceywe
2018-03-13 09:30:21 +08:00
@luckyqiang 只是没安装 python 依赖的问题,用 python 几安装几的
luckyqiang
2018-03-13 10:06:01 +08:00
@chaunceywe python3-dev is already the newest version (3.5.1-3). 应该安装了吧
luckyqiang
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
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
2018-03-13 10:19:02 +08:00
这是我用 Django/Flask 开发的个人博客,uwsgi+nginx 我是这么部署的,没有出现你这种报错,你可以将虚拟环境卸载了重新创建一个,按照我的方法试试?
我的 Github 里面还有相应的配置文件,都开源出来了,可以参考下。

http://www.vua.sh/#7974a888-0a55-488b-b48b-23dcdd6826ac
Kirikora
2018-03-13 10:23:05 +08:00
@luckyqiang uwsgi 也装在虚拟环境里,然后调用虚拟环境里的 uwsgi 试试?
Kirikora
2018-03-13 10:26:13 +08:00
luckyqiang
2018-03-13 20:24:03 +08:00
@xvx 我是把本地的虚拟环境也打包上去了 估计就是那个问题 本地是 python3.6 服务器好像是 3.5
xvx
2018-03-14 08:47:27 +08:00
@luckyqiang 不建议这么干。一般虚拟环境都是在服务器上面部署时创建的,本地环境跟服务器环境有些版本、依赖不一致,你最好是在服务器上面新建一个虚拟环境。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/437412

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX