cp2004 / Octoprint-Upgrade-To-Py3

A script to move an existing OctoPrint install from Python 2 to Python 3
GNU General Public License v3.0
62 stars 7 forks source link
octoprint python3 upgrade-tool

Upgrade your OctoPrint install to Python 3!

Many new plugins only support Python 3, and do not support Python 2 anymore. If you get a message like this installing a plugin:

ERROR: Package 'OctoDash-Companion' requires a different Python: 2.7.16 not in '>=3.3, <4'

You need to upgrade your OctoPrint install to use Python 3, rather than Python 2.

You have several options, depending on how you have installed OctoPrint:

Re-flashing your OS

This is the easiest way to upgrade if you are using OctoPi, since you can re-flash the base OS and it is using Python 3.

  1. Take a backup from inside OctoPrint's 'Backup and Restore' tab, and download it.
  2. Download & install OctoPi 0.18
  3. Once installed, you can restore your backup using 'Backup and Restore' again.

Using this script

Requirements

If you don't meet the above requirements, then please see 'What can I do if my system is not supported' below.

Running the script

Run the following 2 commands in the OS terminal (either through SSH or a connected keyboard/monitor) to start the upgrade:

curl -L https://get.octoprint.org/py3/upgrade.py --output upgrade.py
python3 upgrade.py

If you are not running OctoPi, you will be prompted to provide:

You may also be asked to provide the sudo password so the script can install python3-dev, a package required to install some plugins. (If your machine is not running passwordless sudo)

Once the install has finished (and you have tested it works, of course) you can safely remove the folder /path/to/venv.bak containing your old Python 2 environment.

On an OctoPi install, this would be at /home/pi/oprint.bak

Command line options

There are two command line options available, which you can use. Both optional:

Returning to the old install

If the install fails, then you can safely return to the old install by restoring the backup. It is just the old environment renamed, so you can move it back to it's original position.

You can use the other script in this repo, go_back.py to return to the old install. Usage is similar to the upgrade script:

curl -L https://raw.githubusercontent.com/cp2004/Octoprint-Upgrade-To-Py3/master/go_back.py --output go_back.py
python3 go_back.py

What do I do if my system is not supported?

OctoPi 0.16 or earlier

OctoPrint is only compatible with Python 3.6+. As a result, on earlier versions of OctoPi that were not based on Debian Buster, it is not possible to run this script on those OctoPi versions, since they don't have a new enough Python install available.

Recommended route to Python 3

Manual installs

If you are running Windows, MacOS or your system does not work with this script for whatever reason, then you will need to perform the upgrade manually.

The basic steps boil down to this:

For more detailed steps, please refer to the OS specific install guides on the download page

Blog post

For a full explanation of why this script is here, please make sure to read the blog post I wrote about this on the OctoPrint blog: Upgrade Your OctoPrint Install to Python 3!

Limitations of this script

Contributing

Please open an issue if you find something wrong, or have a feature request. If you would like to make a PR, please do so against the devel branch as master is the download branch for users and I don't want changes that accidentally break something! If your are making a PR for a big feature, please open an issue first so we can discuss.

Sponsors

As well as 2 others supporting me regularly through GitHub Sponsors!

Supporting my efforts

GitHub Sponsors

I created this project in my spare time, and do my best to support the community with issues and help using it. If you have found this useful or enjoyed using it then please consider supporting it's development! ❤️. You can sponsor monthly or one time, for any amount you choose.

Check out my other plugins

You can see all of my published OctoPrint plugins on the OctoPrint Plugin Repository! Or, if you're feeling nosy and want to see what else I'm working on, check out my GitHub profile.

🔨