πŸ‡ΊπŸ‡¦ We stand with Ukraine! πŸ‡ΊπŸ‡¦

My OctoPrint update fails with "ImportError: cannot import name NullHandler"

Earlier versions of the third party plugin PrintTimeGenius pulled in an unneeded third party logging module that is incompatible to Python's standard library. Its presence causes this issue. PrintTimeGenius has since been updated to no longer pull in this disrupting dependency, but if you installed an older version of it at some earlier point it will still have pulled it in and cause errors like the following when attempting to update:

Complete output from command /home/pi/oprint/bin/python2 /home/pi/oprint/local/lib/python2.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-pwPZqO/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple --extra-index-url https://www.piwheels.org/simple -- setuptools wheel Cython:
  Traceback (most recent call last):
    File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
      "__main__", fname, loader, pkg_name)
    File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
      exec code in run_globals
    File "/home/pi/oprint/lib/python2.7/site-packages/pip/__main__.py", line 16, in <module>
      from pip._internal import main as _main  # isort:skip # noqa
    File "/home/pi/oprint/lib/python2.7/site-packages/pip/_internal/__init__.py", line 19, in <module>
      from pip._vendor.urllib3.exceptions import DependencyWarning
    File "/home/pi/oprint/lib/python2.7/site-packages/pip/_vendor/urllib3/__init__.py", line 26, in <module>
      from logging import NullHandler
ImportError: cannot import name NullHandler

The offending module has to be removed to fix things. You can use this single file plugin for this:

https://get.octoprint.org/plugins/cleanup_logging.py

Just enter Plugin Manager, click on Get More and enter the above into the URL field, then click "Install":

Note that the plugin will only work on Python 2 because the logging module in question here will also only work on Python 2. Python 3 instances should not run into this problem at all.

The plugin will not give you any visual feedback but only produce output in octoprint.log like this:

2021-10-12 15:15:37,263 - octoprint.plugins.cleanup_logging - INFO - Found PrintTimeGenius' logging left over, removing...
[...]
2021-10-12 15:15:40,634 - octoprint.plugins.cleanup_logging - INFO - pip uninstall logging returned status code 0
2021-10-12 15:15:40,635 - octoprint.plugins.cleanup_logging - INFO - STDOUT:
Uninstalling logging-0.4.9.6:

  Successfully uninstalled logging-0.4.9.6

2021-10-12 15:15:40,636 - octoprint.plugins.cleanup_logging - WARNING - STDERR:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support

2021-10-12 15:15:40,636 - octoprint.plugins.cleanup_logging - INFO - logging successfully removed

Once it has run its course, restart the server. You can uninstall the plugin again.

:warning: If you have run into this error, you still have not upgraded to Python 3

This error only occurs on legacy Python 2 installs. You can find out how to upgrade here.


Alternatively, you can also uninstall the offending module through the command line via pip uninstall logging.

For OctoPi:

  1. SSH into your Pi (username: pi, default password: raspberry)
  2. Execute ~/oprint/bin/pip uninstall logging

The update should then run through.

18 Likes

I'm just amazed of the level of support provided for this free (but amazing) tool. Got hit by this upgrade issue, but the OctoPrint UI nicely lead me to this post. The way it is documented and then the process of fixing (running a simple plugin) -- hat off for very solid work, and thanks for making it so smooth sailing, Gina!

– Happy user and sponsor!

9 Likes