i cant get litespeed django venv to wrok .

Posted May 6, 2019 4.3k 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?

1 comment

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.

Submit an Answer
11 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,

I have the same problem please your support community

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!


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
  3. 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 /usr/local/lsws/Example/html/demo/demo/
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {
            'read_default_file': '/etc/mysql/my.cnf',
  • Create MySQL credentials nano /etc/mysql/my.cnf [client] 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 blogdata.authuser

by Jeremy Morris
In this tutorial, you will learn how to set up the initial foundation for a blog website with connections to a MySQL database. This will involve creating the skeleton structure of the blog web application using django-admin, creating the MySQL database and then connecting the web application to the database.
Previous 1 2 Next