Skip to content

Instantly share code, notes, and snippets.

@foosel

foosel/README.md Secret

Last active Mar 7, 2022
Embed
What would you like to do?
OctoPrint plugin to downgrade pip 22 to 21.3.1 to work around an issue between OctoPrint < 1.8.0 and pip >= 22

Usage

Read and complete all steps below!

  1. Verify your pip version is 22 or higher via the System info:

    image

    image

    If not, this plugin won't work!

  2. Install this plugin via OctoPrint's plugin manager: Get More, from URL, enter https://gist.githubusercontent.com/foosel/4d2d34d7689a07b6d506d9508fc115f4/raw/downgrade_pip_22.py:

    image

  3. Restart OctoPrint

  4. Restart OctoPrint again

  5. Verify your pip version is now 21.3.1:

    image

  6. Uninstall the plugin again:

    image


If OctoPrint is now prompting you to upgrade pip

  1. Go into Settings > Software Update

  2. Click on the wrench button to open the plugin config

  3. Untick the checkbox "Enable pip update checks

    image

  4. Save

import octoprint.plugin
from octoprint.util.pip import create_pip_caller
from octoprint.util.version import get_comparable_version
class DowngradePip22Plugin(octoprint.plugin.StartupPlugin):
def on_after_startup(self):
import pkg_resources
try:
pip = pkg_resources.get_distribution("pip")
except pkg_resources.DistributionNotFound:
self._logger.info("pip not installed (O_O), can't proceed")
return
pip_version = get_comparable_version(pip.version)
if pip_version < get_comparable_version("22"):
self._logger.info("pip version is {}, no downgrade needed".format(pip.version))
return
self._logger.info("Found pip 22+, downgrading...")
pip_caller = create_pip_caller()
pip_code, pip_out, pip_err = pip_caller.execute("install", "pip==21.3.1")
self._logger.info("pip downgrade returned status code {}".format(pip_code))
self._logger.info("STDOUT:\n{}".format("\n".join(pip_out)))
self._logger.warning("STDERR:\n{}".format("\n".join(pip_err)))
if pip_code == 0:
self._logger.info("pip successfully downgraded to 21.3.1")
else:
self._logger.warning("pip could not be downgraded to 21.3.1")
__plugin_pythoncompat__ = ">=2.7,<4"
__plugin_implementation__ = DowngradePip22Plugin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment