Upgrade from Python 3.6.x to 3.8.x ob Ubuntu 18.04/20.04

I've just upgraded my home server from Ubuntu Server 18.04 LTS to 20.04, which also comes with a new Python 3 version.

I'm (or was) running multiple Octoprint instances with a system user named "octoprint".

Each instance has its own virtual environment (venv), created with Python 3.6.x. Everything was running fine.

Now after the upgrade, I have a newer Python 3 version and it seems, I can't simply use the existing venvs, since the local site-packages aren't installed for the new version.

I found the --upgrade option for the venv module/command and executed this for every venv, which seemed to work, since the config file inside the venv now says Python version is "3.8.x" instead of 3.6.x (sorry, I forgot the minor versions...).

But that doesn't seemed to solve the basic issue, that I don't have the necessary Python packages installed for thr new version.

Now I wonder, how to get all packages which are installed in the old directory to be installed in the new one? Simply copying seems like a bad idea, I guess.... I could install OctoPrint, but what about the plugins?

This seems overly complicated for a minor (Python) version upgrade. Is there a "officially" recommended way or tool/command to do this?

I've now installed the packages using pip and then installed the plugin using the OctoPrint web interface (Plugin Manager).

I had got some error or warning messages for the first instance, since I didn't had wheel installed.

This is what I did (maybe wrong or there is a better solution!):

$ rm -r .cache/pip
$ python3 -m venv --upgrade <existing_venv_dir>
$ source <existing_venv_dir>/bin/activate
$ python3 -m pip install --upgrade pip
$ python3 -m pip install setuptools wheel
$ python3 -m pip install octoprint
$ exit
(Starting instance via systemd)

I was going to reply to this, I made the 'Upgrade to Py3' script, could probably do something similar for this. Definitely something I can see coming up in the future as we try and drop python versions as we go.

1 Like

Yes, I think that would make sense.

I'm not sure if something like this already exist, but what would help -- maybe also in other situations, like re-install -- is a way of exporting a list of the currently installed plugins (by Python package name). This could then be used with pip or maybe even inside the Plugin Manager to automatically (re)install all these plugin (if they still exist).

I've created a 'plugin list' export function from the plugin manager for the next version of OctoPrint (1.6.0). Not done the import bit yet, but will probably do so before it's release so they go together. So it's already kind of on my mind, since just updating the venv doesn't really necessitate the full backup/restore.