Question

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 manage.py runserver 0.0.0.0:8000” 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?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

https://docs.litespeedtech.com/cloud/images/django/#how-do-i-switch-sqlite-to-mysql

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:
PYTHONPATH=/usr/local/lsws/Example/html/lib/python3.6:/usr/local/lsws/Example/html/demo
LS_PYTHONBIN=/usr/local/lsws/Example/html/bin/python
  • Ubuntu 20:
PYTHONPATH=/usr/local/lsws/Example/html/lib/python3.8:/usr/local/lsws/Example/html/demo
LS_PYTHONBIN=/usr/local/lsws/Example/html/bin/python

Let us know if you need any help.

Best, Eric

Hi,

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
mysql>

CREATE DATABASE blog_data;
CREATE USER 'djangouser'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL ON blog_data.* TO 'djangouser'@'%';
FLUSH PRIVILEGES;
  • Edit django DB settings
/usr/local/lsws/Example/html/demo/demo/settings.py
DATABASES = {
    '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 manage.py migrate

We can try to verify the mysql DB

  1. mv db.sqlite3 to other place

  2. Create superuser

python3 manage.py 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!