i cant get litespeed django venv to wrok .

Posted May 6, 2019 1.6k views
DjangoUbuntu 18.04

I am using the Django OpenLiteSpeed One-Click app. I can’t get OpenLiteSpeed beyond the example site.

I get 503 or it just keeps loading. In the log I get:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named ‘encodings’

All I need to do to break it is set the example to use Mysql.

If you change back to sqllite3 it works fine. I know it work because if i use the django test server “python runserver” so the venv is setup correctly.

I have tried adding to the context:
Any Ideas?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

7 answers


How about keep PYTHONHOME=/usr/local/lsws/Example/venv/ only in the Environment?



Yes that was the 1 st thing I did. I just tried again and I get the same result.

Understood, we will try to reproduce it locally first and update you soon.

The only way I could get things to work was to remove PYTHONHOME=/usr/local/lsws/Example/venv/ then copy all my modules to /usr/local/lib/python3.6/dist-packages.
This is a work around and not using venv.


Could you please provide a detail step for how to trigger/reproduce it ?

All I need to do to break it is set the example to use Mysql.

I set it to mysql , but it works on my test server.

Best regards,

Below are the steps to break it. I just tried this whit the same results. Can you provide the context of you tested and the I would like to see it.

Here are the steps.

cd /usr/local/lsws/Example/

virtualenv -p python3 venv

source venv/bin/activate

pip install django

django-admin startproject testapp

vi testapp/testapp/


STATICURL = ’/testapp/static/’
ROOT = ’/usr/local/lsws/Example/testapp/public/static’

cd testapp

mkdir -p public/static
python collectstatic

chown -R nobody:nogroup /usr/local/lsws/Example/testapp

Set up Context
Type = App Server

URI = /testapp/

Location = /usr/local/lsws/Example/testapp

Binary Path = /usr/local/lsws/fcgi-bin/lswsgi

Application Type = WSGI

save and recycle litespeed

goto http://xxxx/testapp/admin

test and it will work

edit Context add

Environment = PYTHONHOME=/usr/local/lsws/Example/venv/

save and recycle litespeed

test and it will work

Now for the fun.

vi testapp/testapp/

comment out the sqllite3.


‘default’: {
'NAME’: 'testappdb’,
'ENGINE’: 'mysql.connector.django’,
'USER’: 'testuser’,
'PASSWORD’: 'testuser’,
'HOST’: '’,
'autocommit’: True,
'charset’: 'utf8mb4’,

pip install django-mysql

pip install mysql-connector-python==8.0.5 (I use this version because the newer ones have too many problems)

test and it will give 503 or 500 or just spin.

python runserver

goto http://xxxx:8000/testapp/admin

This will work.


I followed your steps , however I noticed that you miss one conf

below context setting up “Application Type”, the line “startup file” , could you please add this ?


this is my , the part about DB

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django',
        'USER': 'django',
        'PASSWORD': '123456789',
        'HOST': 'localhost',
        'PORT': '',
        'OPTIONS': {
        'autocommit': True,
        'charset': 'utf8mb4',

Did you run migrate?

no 500 or 503 error , however if I remove that startup file line , I do have 500 error

(venv) root@openlitespeed-django-s-1vcpu-1gb-ams3-01:/usr/local/lsws/Example/testapp# curl -I -XGET
HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8
Location: /testapp/admin/login/?next=/testapp/admin/
Expires: Thu, 09 May 2019 13:40:58 GMT
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Content-Length: 0
Date: Thu, 09 May 2019 13:40:58 GMT
Server: LiteSpeed
Connection: Keep-Alive

Best regards,

Submit an Answer