Renku CLI - UserWarning: Distutils was imported before Setuptools

Hello,

I reported a warning (see below) thrown by the Renku CLI while working on WSL for Windows : UserWarning: Distutils was imported before Setuptools · Issue #3650 · SwissDataScienceCenter/renku-python · GitHub

I can now confirm that it also shows up on Linux Mint 21.2 but I am not sure whether I have reported this correctly…

$ renku --version
/home/champost/.local/pipx/shared/lib/python3.10/site-packages/_distutils_hack/__init__.py:18: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
  warnings.warn(
/home/champost/.local/pipx/shared/lib/python3.10/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
2.7.0
$ 

Thanks

Thank you @champost for reporting this warning.

Hey @champost, I just got fed up with this enough myself to resort to extreme measures :hammer_and_pick:

Based on internet searches, this should be moot in recent versions of setuptools. So I simply deleted the _distutils_hack and distutils-precedence.pth from the site-packages directory. So far so good, though ymmv! My best guess is that those are left behind from some older version of setuptools and are not removed when setuptools is updated.

Thanks for the heads up @rrrrrok. Looks like MMDV (My Mileage Does Vary) !

$ rm -rf /home/champost/.local/lib/python3.10/site-packages/distutils-precedence.pth /home/champost/.local/lib/python3.10/site-packages/_distutils_hack/*
$ renku session ls
/home/champost/.local/pipx/shared/lib/python3.10/site-packages/_distutils_hack/__init__.py:18: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
  warnings.warn(
/home/champost/.local/pipx/shared/lib/python3.10/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")


Warning: Cannot get sessions list from 'renkulab': Please run the renku login command to authenticate with Renku.

Hi @champost,

A few things:

  1. from the above, it looks like you removed those packages from the wrong path? i.e. not ~/.local/pipx/shared/lib but ~/.local/lib

  2. I believe I had to reinstall renku and potentially also restart my terminal. :man_shrugging:

  3. Did you upgrade the version of setuptools first? I did pipx upgrade-all which also updates the shared libraries.

Hi @rrrrrok ,

I ran pip install --upgrade setuptools as mentioned here : UserWarning: Distutils was imported before Setuptools · Issue #3650 · SwissDataScienceCenter/renku-python · GitHub and now I am a little lost as to what should be my next step… :thinking:

Would it be possible to update the CLI installation problems section on https://renku.readthedocs.io ? I can then try afresh on a *nix system and see whether I can reproduce warning or not.

Thanks !

As mentioned in the issue you linked, pipx has its own installation of libraries. So a simple pip install will not upgrade those libraries. You should do ~/.local/pipx/shared/bin/pip install -U setuptools. Afterwards make sure you also remove the no longer needed ~/.local/lib/.../site-packages/_distutils_hack and ~/.local/lib/.../site-packages/distutils-precedence.pth