25

I am trying to setup uWSGI with Pyramid, but I am getting this error, when attempting uwsgi --ini-paste development.ini

Python version: 3.2.3

Error message:

uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
Python version: 3.2.3 (default, Oct 19 2012, 20:08:46)  [GCC 4.6.3]
Set PythonHome to /root/path/to/virtualenv
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named encodings

Here is what I have in development.ini

[uwsgi]
socket = /tmp/uwsgi.sock
master = true


processes = 4

harakiri = 60
harakiri-verbose = true
limit-post = 65536
post-buffering = 8192

daemonize = ./uwsgi.log
pidfile = ./pid_5000.pid

listen = 256 

max-requests = 1000

reload-on-as = 128 
reload-on-rss = 96
no-orphans = true

log-slow = true
virtualenv = /root/path/to/virtualenv

I suppose I have checked everything possible, including the following

echo LANG:$LANG LC_CTYPE:$LC_CTYPE
LANG:en_US.UTF-8 LC_CTYPE:

I am using virtualenv and uWSGI was installed while the environment was active. I have also checked that my virtual environment's lib has a package named encoding (pointing to my main python3.2 installation)

I have also checked this answer and this

I had previously installed uWSGI when my virtualenv was not active, but then I installed it properly and removed the executable and py files from previous installation.

Is there a way to get detailed logs, please let me know if there is. Thanks in advance

Community
  • 1
  • 1
Dev Maha
  • 1,133
  • 1
  • 11
  • 24
  • There are great answers below indicating that the virtualenv can be the cause. Another potential candidate is outdated bytecode: For my part, Python 3.5 bytecode interfered on a freshly upgraded system with Python 3.6. Use commands like `pyclean` to remove the bytecode files. – benjaoming Feb 16 '20 at 21:51

9 Answers9

26

Check that

virtualenv = /root/path/to/virtualenv

points to the right path. I solved my error by fixing this mistyped path.

Louis M
  • 4,036
  • 4
  • 21
  • 25
  • 7
    Although it may seem obvious, I fell for that today. Why on earth can't there be an error message to denote that the virtualev path does not exist? God and uwsgi only knows the answer to that – John Paraskevopoulos Dec 13 '17 at 10:26
  • My mistake was that I gave the env path with "/bin/" at the end of it. – vvvvv Oct 08 '21 at 10:41
7

in my case it was basically because I used python 2.7 as main interpreter, and uwsgi choose pyhon3 plugin. You might need to force it using:

plugins=python32

where python32is appropriate name for your pythhon3 plugin.

Have you checked this: uwsgi python3 plugin doesn't work?

Community
  • 1
  • 1
jb.
  • 23,300
  • 18
  • 98
  • 136
3

I also met this problem today, and I tried to set plugins=python34, but it did not work on Ubuntu 14.04 and Python 3.4.3

This is what I did to fix it:

  1. sudo pip uninstall uwsgi

  2. something goes wrong when i run sudo pip install uwsgi, and run this first:

    sudo apt-get install python-dev

  3. (sudo)pip install uwsgi

Community
  • 1
  • 1
bovenson
  • 1,170
  • 8
  • 6
3

Just had the same problem. What I realized afterwards was that I installed uwsgi with pip install uwsgi in the virtualenv. Once I left the virtualenv, I installed uwsgi on the local system with pip3 install uwsgi (notice I wrote pip instead of pip3). So I uninstalled with pip3 uninstall uwsgi and I repeated with pip install uwsgi. Worked like a Charm.

Albêr
  • 145
  • 1
  • 9
2

Run uwsgi command (with your options) just like the following line:

/<path-to-your-virtualenv-bin>/uwsgi --http :8008 --module project.wsgi --venv /<path-to-your-virtualenv> --chdir /<path-to-your-project>

You will find the issues.

Did you miss your module param?

gzerone
  • 2,179
  • 21
  • 24
2

I encountered a similar error message, but with a python version variation:

Python version: 3.4.3 (default, Nov 28 2017, 16:44:58)  [GCC 4.8.4]

This came about from trying to use a python3.6 virtual environment, but uwsgi being setup for python3.4. I re-setup the virtual environment using python3.4 and all was well.

Edward Moffett
  • 958
  • 1
  • 13
  • 25
2

I had similar problem. In my case, the problem was in uid, guid params of uwsgi.ini. www-data user didn't have a permission to run python in virtualenv.

Alex Black
  • 21
  • 1
0

Building upon Edward's answer, I instead reinstalled uWSGI with pip3.6 instead of pip3, Python 3.4.8 being the default Python 3 on the server:

$ python3 --version
Python 3.4.8
dtk
  • 2,197
  • 2
  • 26
  • 19
0

Check the path of virtualenv. Make sure you are not using something like this: ~/.virtualenvs/xxx.

The ~ symbol points to the home directory of a user. So with different users, this path will refer to different positions.

If you are not very assured, please move the virtualenv to places like /home/.virtualenvs.

Kalana
  • 5,631
  • 7
  • 30
  • 51
folkboat
  • 167
  • 1
  • 7