quru / qis

Dynamic image server for web and print
https://quruimageserver.com
GNU Affero General Public License v3.0
89 stars 7 forks source link

No module named 'encodings' #31

Closed kanlas-net closed 5 years ago

kanlas-net commented 5 years ago

I am following the installation guide and have a problem with httpd starting python program. OS is Centos 7, locale is en_US.UTF-8

Here is what I found in httpd error log:

Current thread 0x00007fb1adcf6880 (most recent call first):
[Tue Oct 22 18:01:32.200714 2019] [core:notice] [pid 1951] AH00052: child pid 2170 exit signal Aborted (6)
[Tue Oct 22 18:01:32.201642 2019] [core:notice] [pid 1951] AH00052: child pid 2171 exit signal Aborted (6)
Fatal Python error: Py_Initialize: Unable to get the locale encoding
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportErrorImportError: : No module named 'encodings'No module named 'encodings'

I found suggestions to fix python path variables, but I don't have them and manually invoking python commands with UTF-8 encodings works well. Also I tried to install latest python3 from centos repository and compile mod_wsgi from pip, but got the same error.

qururoland commented 5 years ago

This sort of issue is usually due to confusion in where the PYTHONHOME and PYTHONPATH environment variables point to, frequently caused by multiple installs of python. This then can be confused by the user account that is running the python - in our case the user "qis". To debug this, try sshing to your server and changing user to qis: ssh <myserver> sudo su qis Then from there just run up python: python3 That should produce the same error as you are getting in the httpd logs. If it is, you need to edit either /etc/profile or /home/qis/profile and add: export PYTHONHOME=<path to your installed python3> export PYTHONPATH=<path to your installed python3>

Hope that helps!

fozcode commented 5 years ago

This does look like a version mismatch between Python and mod_wsgi. If you install mod_wsgi with pip you need to use pip3 (pip3 install mod_wsgi) rather than plain pip (which is Python 2's pip).

Don't worry about PYTHONHOME and PYTHONPATH as the image server doesn't use those.

But the problem here could be that Centos 7's python3 package today is Python 3.6 while the Centos libraries you need from the releases page - QIS-libs-centos-7-py35-x86_64.tar.gz - are compiled for Python 3.5. Centos 7 did not originally provide a python3 package at all, it must have been added recently. The install guide needs updating to reflect this.

In the mean time I think you will need to yum erase python3 and uninstall pip3 and your current version of mod_wsgi. Then follow the install guide to install the EPEL and IUS repos and install the python35u, python35u-pip, and python35u-mod_wsgi packages. Hopefully that will get you going.

kanlas-net commented 5 years ago

@qururoland Thank you for help. As qis is nologin user I tried to execute this command and it works well: sudo -u qis python3.5 Suggested package from IUS repositories make link for python3.5, not python3, that why my command looks so. When I have python3 link from different package, httpd has the same error so that is not an issue I think. Also I can get environment variables where still no PYTHONHOME and PYTHONPATH specified sudo -u qis printenv

[admin@qis ~]$ sudo -u qis env
HOSTNAME=qis.sth.local
TERM=xterm-256color
HISTSIZE=1000
LS_COLORS=*long junk text here*
MAIL=/var/spool/mail/admin
LANG=en_US.UTF-8
PATH=/sbin:/bin:/usr/sbin:/usr/bin
LOGNAME=qis
USER=qis
USERNAME=qis
HOME=/opt/qis
SHELL=/sbin/nologin
SUDO_COMMAND=/bin/env
SUDO_USER=admin
SUDO_UID=1000
SUDO_GID=1000
XDG_SESSION_ID=1
HOME=/opt/qis
SHELL=/sbin/nologin
SUDO_COMMAND=/bin/printenv
SUDO_USER=root
SUDO_UID=0
SUDO_GID=0
XDG_SESSION_ID=1
kanlas-net commented 5 years ago

@fozcode I made a clean install of CentOS 7 and follow your guide as is, line by line. And get the error I posted here... Yes, I use pip3 for compiling mod_wsgi, version mismatch was the first I think about. Maybe IUS repo has version mismatch?

fozcode commented 5 years ago

OK. Normally you would not install mod_wsgi with pip, just installing the python35u-mod_wsgi package gives you everything you need.

If this is what you have done I'll run through a clean install and try to reproduce the problem. It's been 18 months since I last tried it and as you say something could have changed in IUS or in one of the other packages.

kanlas-net commented 5 years ago

@fozcode I tried to install python35u-mod_wsgi at first and only after httpd failure I tried to compile it. Are you planning to support python 3.6 in your product?

fozcode commented 5 years ago

Update: I've been able to reproduce the same problem, working on a fix.

@1Stedy Python 3.6 is supported (and this is the default on Ubuntu 18). We'll move CentOS over to 3.6 once we move from CentOS 7 to 8, but CentOS 8 is still a bit too new at the moment.

fozcode commented 5 years ago

So the problem is that QIS-libs-centos-7-py35-x86_64.tar.gz is missing a symlink entry that causes mod_wsgi to fail to recognise /opt/qis as a Python home. The fix is:

sudo systemctl stop httpd
cd /opt/qis
sudo -u qis ln -s lib lib64
sudo systemctl start httpd

Over the years this lib64 symlink seems to come and go depending on the version of Python / virtualenv / pip / setuptools. It looks like we need to make sure it's always present.

fozcode commented 5 years ago

The libs for the latest release have been rebuilt to include that missing lib64 symlink and the files replaced for v4.1.4 on releases. I have also tested the install on a fresh CentOS 7 VM and it all started up OK this time. So hopefully this is fixed now.

kanlas-net commented 5 years ago

I tried solution with symlink and it works. Thank you! I think issue can be closed