i cant get litespeed django venv to wrok .

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: PYTHONHOME=/usr/local/lsws/Example/venv/ LS_PYTHONBIN=/usr/local/lsws/Example/venv/bin/python Any Ideas?


have you found a solution ? i have like your problem exactly

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Hi @haujo01 @healthzoneriyadh @bgv ,

I have updated the doc FAQ here in case you need more information.

For some reason you got 500/503, also No module named ‘encodings’ cases, please try updating the environment variable via Web Admin > Virtual Hosts > Context like below:

  • Ubuntu 18:
  • Ubuntu 20:

Let us know if you need any help.

Best, Eric


It’s been a while so I tried to setup mysql with OLS Django again, and it still works.

Here’s my steps.

  1. Launch OpenLiteSpeed Django Image
  2. Active virtual environment by command
source /usr/local/lsws/Example/html/bin/activate
  1. Follow DigitalOcean guide to
  • Install packages
apt install mysql-server -y
apt install python3-dev libmysqlclient-dev default-libmysqlclient-dev -y
pip3 install mysqlclient
  • Create the Database
sudo mysql -u root

CREATE USER 'djangouser'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL ON blog_data.* TO 'djangouser'@'%';
  • Edit django DB settings
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {
            'read_default_file': '/etc/mysql/my.cnf',
  • Create MySQL credentials
nano /etc/mysql/my.cnf
database = blog_data
user = djangouser
password = password
default-character-set = utf8
  • Reload DB
systemctl daemon-reload
systemctl restart mysql
  • Apply changes to Django
python3 migrate

We can try to verify the mysql DB

  1. mv db.sqlite3 to other place

  2. Create superuser

python3 createsuperuser

Now you should see an entry generated under blog_data.auth_user

I have this exact same problem.

It specifically has to do with the PYTHON environment. When I remove that it works fine. When I keep it in, it doesn’t.

Any progress on a solution? It’s been over a year!

I have the same problem please your support community


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,

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/

change ALLOWED_HOSTS = [‘*’]

add STATIC_URL = ‘/testapp/static/’ 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.


DATABASES = { ‘default’: { ‘NAME’: ‘testappdb’, ‘ENGINE’: ‘mysql.connector.django’, ‘USER’: ‘testuser’, ‘PASSWORD’: ‘testuser’, ‘HOST’: ‘’, ‘OPTIONS’: { ‘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.


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,

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.

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


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