How to upgrade erpnext from python 3.5 to 3.8

Please let me know how to upgrade python 3.5 to python 3.8.

I have gone through different forum posting and nothing helps me to do this.

Any formal guide to upgrade ?

First, you need to have python 3.8 installed on your server. Then, there’s a bench command to migrate your python environment. Please be sure to make a full backup of your server before doing this.

bench migrate-env /path/to/python38

(Replace /path/to/python38 with the real path. For example, /usr/bin/python3.8)

1 Like

Here are the steps I have followed

wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tar.xz
tar xf Python-3.8.6.tar.xz
cd ./Python-3.8.6
./configure
make
make install
update-alternatives --install /usr/bin/python python /usr/local/bin/python3.8 10
bench migrate-env /usr/local/bin/python3.8

and got me this

sanath@vmi322732:~/frappe-bench$ bench migrate-env /usr/local/bin/python3.8
/bin/sh: 1: /home/sanath/frappe-bench/env/bin/python: not found

DEBUG:bench.utils:Clearing Redis Cache…
$ /usr/bin/redis-cli -p 13000 FLUSHALL
OK
DEBUG:bench.utils:Clearing Redis DataBase…
$ /usr/bin/redis-cli -p 13000 FLUSHDB
OK
DEBUG:bench.utils:Backing up Virtual Environment
Traceback (most recent call last):
File “/usr/local/bin/bench”, line 11, in
load_entry_point(‘bench’, ‘console_scripts’, ‘bench’)()
File “/home/sanath/.bench/bench/cli.py”, line 41, in cli
bench_command()
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 764, in ca ll
return self.main(*args, **kwargs)
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 1137, in inv oke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 956, in invo ke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python3.5/dist-packages/click/core.py”, line 555, in invo ke
return callback(*args, **kwargs)
File “/home/sanath/.bench/bench/commands/utils.py”, line 182, in migrate_env
migrate_env(python=python, backup=backup)
File “/home/sanath/.bench/bench/utils.py”, line 1085, in migrate_env
os.rename(source, dest)
FileNotFoundError: [Errno 2] No such file or directory: ‘/home/sanath/frappe-ben ch/env’ -> ‘/home/sanath/frappe-bench/20201204_172040’

Any idae?

I have found that once we execute migration cmd

(bench migrate-env /usr/local/bin/python3.8)

the env folder of frappe-bench has renamed to archived_envs.
Then the error said no file directory on frappe-bench/env

Any idea how to resolve this?

sudo apt install python3.8 python3.8-venv python3.8-doc python3.8-dev

bench migrate-env python=python3.8

bench setup requirements

root@vmi322732:~# sudo apt install python3.8 python3.8-venv python3.8-doc python3.8-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package python3.8
E: Couldn’t find any package by glob ‘python3.8’
E: Couldn’t find any package by regex ‘python3.8’
E: Unable to locate package python3.8-venv
E: Couldn’t find any package by glob ‘python3.8-venv’
E: Couldn’t find any package by regex ‘python3.8-venv’
E: Unable to locate package python3.8-doc
E: Couldn’t find any package by glob ‘python3.8-doc’
E: Couldn’t find any package by regex ‘python3.8-doc’
E: Unable to locate package python3.8-dev
E: Couldn’t find any package by glob ‘python3.8-dev’
E: Couldn’t find any package by regex ‘python3.8-dev’

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update

HEY! USE SCREEN root@vmi322732:~# sudo add-apt-repository ppa:deadsnakes/ppa
sudo: add-apt-repository: command not found

I am using Debian 9

Any one have the solution for this?

Hi Sanath: Did you manage to find a solution for this?

Thanks

Jay

I just follow the below guide

Recently Frappe updated it’s dependencies so that you’ll get an error on update in case you’re using python < 3.7.

Here’s what I did to upgrade to python3.8 under Ubuntu (18.04 and 20.04). This is a more detailed version of my quick note on GitHub.

:bangbang: Remember to take a backup of your server first! :bangbang:

Install python and python-dev packages for 3.8:

sudo apt install python3.8 python3.8-dev

Switch to your bench directory:

cd /home/frappe/frappe-bench

Now you could, in theory, run bench migrate-env python3.8 and be done. But this produced an error for me, so I had to do everything manually instead. Let me know if bench migrate-env works for you!

Move your old python env folder to env-old. This way you make space for the new env while keeping a copy to restore in case something goes wrong.

mv env env-old

Create a new python environment with python3.8

virtualenv --python python3.8 env

In case the above command doesn’t work (I had problems on one machine) you can try this alternative:

python3.8 -m venv env

Upgrade pip to the newest version. The later commands will fail in case your pip version is too old.

env/bin/pip install -U pip

Now we can reinstall our apps and their dependencies. Here I only show frappe and erpnext. Please append all your custom apps to the command like this: -e apps/my-app

env/bin/pip install -e apps/frappe -e apps/erpnext

I like to run bench update at the end to see if everything worked:

bench update --reset

If everything went well you can delete your old env (optional, use with care):

rm -rf env-old
17 Likes
Traceback (most recent call last):
  File "/home/frappe/.local/bin/bench", line 8, in <module>
    sys.exit(cli())
  File "/home/frappe/.local/lib/python3.6/site-packages/bench/cli.py", line 121, in cli
    raise e
  File "/home/frappe/.local/lib/python3.6/site-packages/bench/cli.py", line 111, in cli
    bench_command()
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/.local/lib/python3.6/site-packages/bench/commands/utils.py", line 175, in migrate_env
    migrate_env(python=python, backup=backup)
  File "/home/frappe/.local/lib/python3.6/site-packages/bench/utils/bench.py", line 172, in migrate_env
    os.mkdir(parch)
FileNotFoundError: [Errno 2] No such file or directory: '/home/frappe/v13-bench/archived/envs'

I am getting the above error on running bench migrate-env python3.8

This error can be temporarily fixed by adding the directory: /archived/envs in your bench folder.

I have created an issue here: https://github.com/frappe/bench/issues/1279

Update:
After this I got the following error:

/home/frappe/v13-bench/env/bin/python: Error while finding module specification for 'frappe.utils.bench_helper' (ModuleNotFoundError: No module named 'frappe')

Bench command cache doesn't exist in this folder!

This was fixed by running bench setup env

Update 2:
bench setup env” command (or some other above command) removed all my apps from site/apps.txt

I ended up using your below command to solve it.

2 Likes

Thanks for reporting!

Worked like a charm for me,

Thank you!

This worked for me. thanks :slight_smile:

Issue resolved, thanks for sharing such tips which I was looking for upgradation.

Primo Capital