Sergey
Sergey

Reputation: 21201

uWSGI Fatal Python error: Py_Initialize: Unable to get the locale encoding

I've seen at least 3 questions about this problem.

  1. Virtualenv (Python 3.2)
  2. Django project in this env
  3. uWSGI

But I have plugins = python3 in uWSGI settings file and it's ok!
Server is started, everything is working...
Restart server - and everything is still working...
Reload server (or touch reload-file) and you have this error:

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

Even more... I have another project in another Env and touch reload-file works for it.
Any suggestions why can this happen?

PS: I tried to create a new virtualenv

Logs:

After service uwsgi restart:

...
Sun Dec 29 22:57:21 2013 - detected max file descriptor number: 1024
Sun Dec 29 22:57:21 2013 - lock engine: pthread robust mutexes
Sun Dec 29 22:57:21 2013 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/test/socket fd 3
Sun Dec 29 22:52:59 2013 - uwsgi socket 1 bound to TCP address 127.0.0.1:3045 fd 5
Sun Dec 29 22:52:59 2013 - Python version: 3.2.3 (default, Sep 25 2013, 19:38:45)  [GCC 4.7.2]
Sun Dec 29 22:52:59 2013 - Set PythonHome to /pyenvs/test/
Sun Dec 29 22:52:59 2013 - Python main interpreter initialized at 0x688cc0
Sun Dec 29 22:52:59 2013 - threads support enabled
Sun Dec 29 22:52:59 2013 - your server socket listen backlog is limited to 10000 connections
Sun Dec 29 22:52:59 2013 - *** Operational MODE: preforking ***
Sun Dec 29 22:52:59 2013 - WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x688cc0 pid: 1619 (default app)
Sun Dec 29 22:52:59 2013 - *** uWSGI is running in multiple interpreter mode ***
Sun Dec 29 22:52:59 2013 - spawned uWSGI master process (pid: 1619)
Sun Dec 29 22:52:59 2013 - spawned uWSGI worker 1 (pid: 1628, cores: 1)
Sun Dec 29 22:52:59 2013 - spawned uWSGI worker 2 (pid: 1629, cores: 1)

After service uwsgi reload:

Sun Dec 29 22:55:31 2013 - *** Starting uWSGI 1.2.3-debian (64bit) on [Sun Dec 29 22:55:31 2013] ***
...
Sun Dec 29 22:55:31 2013 - detected max file descriptor number: 1024
Sun Dec 29 22:55:31 2013 - lock engine: pthread robust mutexes
Sun Dec 29 22:55:31 2013 - uwsgi socket 0 inherited UNIX address /run/uwsgi/app/test/socket fd 3
Sun Dec 29 22:55:31 2013 - uwsgi socket 1 inherited INET address 127.0.0.1:3045 fd 5
Sun Dec 29 22:55:31 2013 - Python version: 3.2.3 (default, Sep 25 2013, 19:38:45)  [GCC 4.7.2]
Sun Dec 29 22:55:31 2013 - Set PythonHome to /pyenvs/test/
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named encodings

Update 1

It is definitely virtual env. Copying my old VEnv and using didn't cause this problem.
Still have no idea why a newly created one doesn't work.
Copying only python executable didn't help.

Upvotes: 1

Views: 7815

Answers (1)

Sergey
Sergey

Reputation: 21201

I don't know exactly what happened since I did a lot of things:

  1. System upgrade
  2. New python environment
  3. Python version 3.3, not 3.2
  4. uwsgi 1.2.4 system package (perhaps this helped)
    or better use pip install uwsgi in your VE and run what you need with supervisord

Now it's working. Thanks roberto.

Upvotes: 1

Related Questions