Impossible to upgrade from v11.1.56 to version-12

Hello,

I am using this command to upgrade:

bench switch-to-branch version-12 frappe erpnext --upgrade

using frappe user and inside frappe-bench folder.

After some processing, this error occurs:

> erpnext/accounts/doctype/item_tax_template_detail/item_tax_tem

Aborting
Error switching to branch version-12 for erpnext
Updating Python libraries…
INFO:bench.utils:./env/bin/pip install --upgrade pip
Traceback (most recent call last):
File “./env/bin/pip”, line 6, in
from pip._internal import main
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pip/_internal/init.py”, line 40, in
from pip._internal.cli.autocompletion import autocomplete
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pip/_internal/cli/autocompletion.py”, line 8, in
from pip._internal.cli.main_parser import create_main_parser
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pip/_internal/cli/main_parser.py”, line 11, in
from pip._internal.commands import (
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pip/_internal/commands/init.py”, line 6, in
from pip._internal.commands.completion import CompletionCommand
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pip/_internal/commands/completion.py”, line 6, in
from pip._internal.cli.base_command import Command
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pip/_internal/cli/base_command.py”, line 26, in
from pip._internal.index import PackageFinder
ImportError: cannot import name PackageFinder
Traceback (most recent call last):
File “/usr/bin/bench”, line 11, in
load_entry_point(‘bench’, ‘console_scripts’, ‘bench’)()
File “/home/frappe/.bench/bench/cli.py”, line 40, in cli
bench_command()
File “/usr/lib64/python2.7/site-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/usr/lib64/python2.7/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/usr/lib64/python2.7/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/lib64/python2.7/site-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/lib64/python2.7/site-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/frappe/.bench/bench/commands/update.py”, line 138, in switch_to_branch
switch_to_branch(branch=branch, apps=list(apps), upgrade=upgrade)
File “/home/frappe/.bench/bench/app.py”, line 397, in switch_to_branch
switch_branch(branch, apps=apps, bench_path=bench_path, upgrade=upgrade)
File “/home/frappe/.bench/bench/app.py”, line 383, in switch_branch
update_requirements()
File “/home/frappe/.bench/bench/utils.py”, line 429, in update_requirements
exec_cmd("{pip} install --upgrade pip".format(pip=pip))
File “/home/frappe/.bench/bench/utils.py”, line 161, in exec_cmd
raise CommandFailedError(cmd)
bench.utils.CommandFailedError: ./env/bin/pip install --upgrade pip
frappe@vps [~/frappe-bench]#

How can I solve it?

Regards
Jaime

Maybe check for other reports, for clues on what to try like these


I don’t understand. What is relationship from that “readthedocs” with this error? It seems that “readthedocs” is another product that also uses pip. Solution written in that page is related to “readthedocs” but I don’t have it (or at least, I don’t think I have it).

Please, can you elaborate further?

Thanks

Hi Jaime - Looks like you’re using Python 2.7. I believe ERPNext 12 is only supporting Python 3 now. That may be part of the problem.

During the upgrade, it appears pip is trying to upgrade itself. But cannot:

pip install --upgrade pip

‘Package Finder’ is a component of pip. I don’t know the inner workings, but here’s a link:
https://pip.pypa.io/en/stable/development/architecture/package-finding/

While this doesn’t solve your problem, hopefully it helps point you in a good direction.

@brian_pond yes, you are right. I have Python 2.7.

But ERPNext uses its own pip environment, doesn’t it? Can Python 3 be installed only to be used by ERPNext?

Regards
Jaime

Short answer: Yes, ERPNext works within its own Python virtual environment. However, that virtual environment is created -by- Python. If you want a Python 3.6 virtual environment, you create that environment using Python 3.6. So you’ll need to install it on your machine.

Longer explanation:
You can have as many Python(s) on your host as you want. For example, my laptop has three of them:
Python 2.7.16, Python 3.6.8, and Python 3.7.2.

ERPNext always uses my 3.7.2. Because when I first installed Bench and Frappe, that’s the Python I started with, to build my virtual environments.

The rest of my laptop’s programs know which Python to use, based on Linux symlinks:

# Python 2
/usr/bin/python -> /usr/bin/python2 -> /usr/bin/python2.7
# Python 3
/usr/bin/python3 -> /usr/bin/python3.6

Can you “hide” Python3 from the rest of your machine? I guess you could. If I wanted to do this, I would probably install Python 3 in a weird place. And make sure there were no symlinks pointing to it. In that case, the only way to call Python 3 would be providing the precise path to the binary.

Hi @brian_pond,

Can I use what it is explained in this link https://linuxize.com/post/how-to-install-python-3-on-centos-7/ to have Python 3 and then, switch to that version, then, create the virtual environment by overriding the current environment created when I installed ERPNext 11 and finally, install ERPNext 12? Do you think it will work?

When upgrading ERPNext, Python that is run belongs to /home/frappe/frappe-bench/env folder, instead of the global Python, so it might maybe work. The only doubt if by overriding the current env folder will work.

If something goes wrong, can I just restore the whole frappe-bench folder from a backup? or if I started upgrading, no return will be possible?

Regards
Jaime

  1. Backup everything first. The entire directory containing frappe-bench. Triple check your backups.

  2. I’d also do my initial work either A) Another server. Or B) If on the same server, in a completely different directory.

  3. The file /home/frappe/frappe-bench/env/bin/python isn’t actually Python. It’s a symlink. It points at the real Python on your server. To see what I mean, run this in a terminal:

ls -lA /home/frappe/frappe-bench/env/bin/python*

At this point, I’m just guessing at approaches you might take. I wish there was an Official Answer to your question from the developers, though.

Were it me, I’d probably try to create an empty ERPNext v11, but with a fresh Python3 environment. Go through all the usual installation steps. That should successfully download the Python3 dependencies from PyPi.

Once that was online, I’d restore my MariaDB database and code back into my new environment. Making sure that my ERPNext v11 was running perfectly. And then when all that is done, make the upgrade to v12.

Another option is installing a completely clean ERPNext v12 with Python 3. And then trying to uplift the ERPNext v11 database and code into that environment. I don’t know if the patches would handle that. It’s possible.

Either way, backups are critical. If you mess everything up, you want a way of quickly recovering.

Jaime - Just FYI, while working on Bench code tonight, I noticed there is a command “migrate-env”. Supposedly it migrates your Virtual Environment to another Python?

I’ve never used it, or reviewed its code. But it may help solve some of your challenges.

@Jaime_Stuardo @brian_pond

I’ve used the migrate-env command to change the Python environment on multiple local benches, and I haven’t faced an issue ever, so it’s a safe bet as far as I can tell.

It archives your existing environment too, in case something goes wrong or you need to revert to the old one.

Hello,

I could finally install ERPNext 12.11.2 in my Python 2.7.5 system, but I think I was “lucky”.

The fact is that a hosting problem occured some weeks ago. That hosting crash caused my ERPNext installation got corrupted. Fortunately, database was kept intact, so, I have reinstalled the last version of version-11 branch from scratch.

That was not an easy process since it seems branch names have changed. One of my attempts took me to get ERPNext version 13 beta, huh? I did not understand what happened, but that gave me the clue if version 13 beta supports Python 2.7.5, version 12 should support it also.

Well, then I downgraded from version 13 beta to last version of 11 branch and finally I have restored the old database into the new created one. That way, version 11 was working as before.

Today I had time to try to update to version 12 again, so I followed the easy instructions in this post:

After it, I got an error in redis server, but searching the error, I have run this command:

redis-cli -p 13001 FLUSHALL

Finally, after version 12 was successfully installed, all assets were missing, so the final step was to run this command:

bench update --reset

as this site suggested:

Now, I have this version running in my system:

ERPNext: v12.11.2 (version-12)

Frappe Framework: v12.9.1 (version-12)

Regards
Jaime