App Server Environment not work

mshzsh

New Member
#1
hi,
I tried many times to run django with virtualenv on OpenLightSpeed, but I didn't succeed and I couldn't find a solution on the Internet.
Of course, if I don't use virtualenv and install the packages on the main python system, the problem will be solved, but I need to use virtualenvs.

Everything works fine until I use the following lines :

PYTHONHOME=/usr/local/lsws/Example/venv/
LS_PYTHONBIN=/usr/local/lsws/Example/venv/bin/python

I have tested all the following lines in different order :

PYTHONHOME=/usr/local/lsws/Example/venv/
----------------------------------------------------------------------------------------------------
LS_PYTHONBIN=/usr/local/lsws/Example/venv/bin/python3.8
PYTHONHOME=/usr/local/lsws/Example/venv/
----------------------------------------------------------------------------------------------------
PYTHONHOME=/usr/local/lsws/Example/html/venv
PYTHONPATH=/usr/local/lsws/Example/html/venv/lib/python3.8/site-packages
LS_PYTHONBIN=/usr/local/lsws/Example/html/venv/bin/python3.8
----------------------------------------------------------------------------------------------------
And many other ways ...

I get this error in stderr.log:
"Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'"


Note :
(( virtualenv has no problem and works properly in the cli ))


OS : Pop!_OS 20.04 LTS (ubuntu 20.04)
Python : 3.8
OpenLiteSpeed : 1.6.13
wsgi-lsapi : 1.6
 

Cold-Egg

Administrator
#2
Hi @mshzsh ,

It should works by following the KB here https://openlitespeed.org/kb/python-wsgi-applications/#Set_up_Django_with_a_Virtual_Environment

Set
Code:
PYTHONHOME=/usr/local/lsws/Example/venv/
to environment should be good.

If you have any account with DigitalOCean, GCP, AWS..etc, you can simply launch a django + venv solution from the marketplace immediately to check the settings. https://docs.litespeedtech.com/cloud/images/django/

Also you can try the django + venv setup script on a clean server.
Code:
### Install OpenLiteSpeed and Django
bash <( curl -sk https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/djangosetup.sh )
### Regenerate password for Web Admin, Database, setup Welcome Message
bash <( curl -sk https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Cloud-init/per-instance.sh )
### Reboot server
reboot
Best,
Eric
 

mshzsh

New Member
#3
thanks Eric,
I tested with several different VPS but I had the same problem, and of course I don't want to use cloud servers.

I have another problem that when I edit the settings.py file, the changes are applied with a delay of a few hours, even if I restart the server.
But this does not happen when editing other files
 

Cold-Egg

Administrator
#4
That's fine, I just want to show you the config there works with virtual env :)
Try killing the lswsgi process after you change the settings see if it helps
Code:
killall lswsgi
 
#6
Hi @mshzsh I am facing the exact same problem that you are. Were you able to proceed?

I suspect this is particular to Python 3.8, since I tried using the Django image (which has Ubuntu 18.04 and Python 3.6) and it works fine out of the box. But if I upgrade this image to Ubuntu 20.04 that has Python 3.8, the error is seen. Also if I start with a clean 20.04 and install OLS, that works fine. But once I add wsgi and django (with the same OLS config file from the image), the same error once again.

I also tried with a fresh Debian 10.4 image (Python 3.7.3) and the django install succeeded without a hitch.
 
Last edited:
Top