Python error after 16.04->18.04 upgrade

Tying to upgrade a perfectly running v11 erpnext install on Ubuntu 16.04. to Ubuntu 18.04

running:

sudo apt update
sudo apt upgrade
sudo do-release-upgrade

all works fine. However when I go to

supervisorctl start all 

I get 5 fatal errors.

root@erpnextv12-4:/home/frappe/frappe-bench/logs# supervisorctl start all
frappe-bench-workers:frappe-bench-frappe-default-worker-0: ERROR (spawn error)
frappe-bench-web:frappe-bench-frappe-web: ERROR (spawn error)
frappe-bench-workers:frappe-bench-frappe-long-worker-0: ERROR (spawn error)
frappe-bench-workers:frappe-bench-frappe-short-worker-0: ERROR (spawn error)
frappe-bench-workers:frappe-bench-frappe-schedule: ERROR (spawn error)
frappe-bench-web:frappe-bench-node-socketio: started
frappe-bench-redis:frappe-bench-redis-queue: started
frappe-bench-redis:frappe-bench-redis-cache: started
frappe-bench-redis:frappe-bench-redis-socketio: started

my first problem seems to come in web.error.log

systems@erpnextv12-4:/home/frappe/frappe-bench/logs$ cat web.error.log
[2022-03-15 13:58:46 +0000] [5605] [INFO] Starting gunicorn 19.9.0
[2022-03-15 13:58:46 +0000] [5605] [INFO] Listening at: http://127.0.0.1:8000 (5605)
[2022-03-15 13:58:46 +0000] [5605] [INFO] Using worker: sync
[2022-03-15 13:58:46 +0000] [5667] [INFO] Booting worker with pid: 5667
[2022-03-15 13:58:46 +0000] [5668] [INFO] Booting worker with pid: 5668
[2022-03-15 13:58:46 +0000] [5692] [INFO] Booting worker with pid: 5692
[2022-03-15 13:58:46 +0000] [5693] [INFO] Booting worker with pid: 5693
[2022-03-15 13:58:46 +0000] [5694] [INFO] Booting worker with pid: 5694
[2022-03-15 13:58:46 +0000] [5696] [INFO] Booting worker with pid: 5696
[2022-03-15 13:58:46 +0000] [5697] [INFO] Booting worker with pid: 5697
[2022-03-15 13:58:46 +0000] [5698] [INFO] Booting worker with pid: 5698
[2022-03-15 14:05:55 +0000] [5605] [INFO] Handling signal: term
[2022-03-15 14:05:55 +0000] [5696] [INFO] Worker exiting (pid: 5696)
[2022-03-15 14:05:55 +0000] [5667] [INFO] Worker exiting (pid: 5667)
[2022-03-15 14:05:55 +0000] [5697] [INFO] Worker exiting (pid: 5697)
[2022-03-15 14:05:55 +0000] [5698] [INFO] Worker exiting (pid: 5698)
[2022-03-15 14:05:55 +0000] [5668] [INFO] Worker exiting (pid: 5668)
[2022-03-15 14:05:55 +0000] [5692] [INFO] Worker exiting (pid: 5692)
[2022-03-15 14:05:55 +0000] [5693] [INFO] Worker exiting (pid: 5693)
[2022-03-15 14:05:55 +0000] [5694] [INFO] Worker exiting (pid: 5694)
[2022-03-15 14:05:56 +0000] [5605] [INFO] Shutting down: Master
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007ff5d84c3740 (most recent call first):
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007fbd6a951740 (most recent call first):
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007fb1e91fa740 (most recent call first):
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Now this last makes me think something in the upgrade has messed up my python settings. I am thinking that if I can fix that, the other errors will fall away ?

So can anyone suggest the best way to fix this ? I have already looked at just “fixing python” but that’s a huge topic with no single answer.

Hi,
You can try bench setup supervisor and see if it helps. Also bench update --requirements However upgrading Ubuntu with ERPNext and dependencies without alot of reconfiguration is going to be tough.

If possible set up v11 on a fresh Ubuntu 18 or 20 and restore your ERPnext from a backup.

I just came from trying to setup a fresh erpnext on 18.04 :grinning: and that had realy bad problems too.

Also our current erpnext has a lot of additional customisation.

@Jason_LoCascio what is your python version ?

systems@erpnext-jason:~$ python -V
Python 2.7.17

and

systems@erpnext-jason:~$ apt list python
Listing... Done
python/bionic,now 2.7.15~rc1-1 amd64 [installed,automatic]

and

systems@erpnext-jason:~$ apt list -a python3
Listing... Done
python3/bionic-updates,now 3.6.7-1~18.04 amd64 [installed]
python3/bionic 3.6.5-3 amd64

now the interesting thing is before the upgrade to 18.04, there was:

systems@erpnext:~$ python -V
Python 2.7.12

and

systems@erpnext:~$ apt list python
Listing... Done
python/xenial-updates,now 2.7.12-1~16.04 amd64 [installed,automatic]
N: There is 1 additional version. Please use the '-a' switch to see it
systems@erpnext:~$ apt list python3
Listing... Done
python3/xenial,now 3.5.1-3 amd64 [installed]
systems@erpnext:~$

re: bench setup supervisor

systems@erpnext-jason:~$ bench setup supervisor
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3088, in <module>
    @_call_aside
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3072, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3101, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 574, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 892, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 778, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'bench' distribution was not found and is required by the application

try the following:

sudo apt install python3.8 python3.8-dev python3-pip
sudo pip3 install frappe-bench --upgrade

Is your v11 ERPNext backed up?

erpnet is a clone of the running VM. I can restore it as many times as needed until I get this right so I can apply it to the “real” system.

systems@erpnext-jason:~$ sudo pip3 install frappe-bench --upgrade
Traceback (most recent call last):
File “/usr/local/bin/pip3”, line 6, in
from pip._internal.main import main
ModuleNotFoundError: No module named ‘pip._internal’

try: sudo pip3 install pip --upgrade and then try it again, also use apt to uninstall any python3 versions other than 3.8.

Have progressed a little on my own VM.

    pip needs to be reinstalled
apt-get remove --purge python-pip
curl https://bootstrap.pypa.io/pip/3.6/get-pip.py | sudo python3

    then

sudo pip3 install frappe-bench --upgrade

leaves all but 1 process (frappe-bench-web:frappe-bench-frappe-web) running. web.error.log still shows the same error about python.

Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f59183da740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f4fb4c6f740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f1cd5eb2740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007fd98d860740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007fa868376740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f7134c3c740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007ff90b609740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f9d9ca21740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007fd23ee06740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f28c2306740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f5b5f68c740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f1d13f19740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f59c0330740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f9e089a8740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f81c4589740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007fa61f78d740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007fd978050740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f740ea04740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f8e4d54c740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f142d856740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named ‘encodings’

Current thread 0x00007f6e168e0740 (most recent call first):

A couple things to try:

sudo apt install python3-pip
bench setup env