sahib / rmlint

Extremely fast tool to remove duplicates and other lint from your filesystem
http://rmlint.rtfd.org
GNU General Public License v3.0
1.86k stars 128 forks source link

Getting "cannot import name '_gi' from 'gi'" when running rmlint --gui #543

Closed mYnDstrEAm closed 2 years ago

mYnDstrEAm commented 2 years ago

When I run rmlint --gui on Debian11/KDE it returns:

Failed to load shredder: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)
This might be due to a corrupted install; try reinstalling.

I also tried it with export PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages && rmlint --gui and tried reinstalling it with apt-get.

It used to work so maybe an update or the switch to Wayland broke it.

cebtenzzre commented 2 years ago

Normally that error would indicate there is some circular dependency or other issue within the Python 3 gobject-introspection bindings, but that would be strange. The output of head -1 "$(which shredder)" and python3 -c 'from gi.repository import GObject' (if any) would be useful. Also see if you can run the GUI with python3 -c 'import shredder; shredder.run_gui()'.

mYnDstrEAm commented 2 years ago

I also had problems with MVT(https://github.com/mvt-project/mvt/issues/230) and BiT (https://github.com/bit-team/backintime/issues/1042) and tried updating all packages with pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U (which didn't help) maybe that's related.

head -1 "$(which shredder)" returns: head: cannot open '' for reading: No such file or directory and python3 -c 'from gi.repository import GObject' returns the following:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 40, in <module>
    from . import _gi
ImportError: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)

same error for the other command.

cebtenzzre commented 2 years ago

Hm, I thought there was a shredder launcher in /usr/bin but I'm using the develop branch on Arch so maybe it's different.

Anyway, the issue is related to your installation of the PyGObject package, which is provided by python3-gi on Debian - rmlint needs to be able to import Gtk via gi in order to show a GUI from python.

Make sure python3-gi is installed and run pip uninstall PyGObject to get rid of the user version if any, which could cause issues. Next time you should probably add --user to that pip list command so you don't end up with separate, newer copies of all your system python packages, that is likely to break more than it would fix.

mYnDstrEAm commented 2 years ago

python3-gi was already installed, pip uninstall PyGObject returns:

Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 5, in <module>
    from pip._internal.cli.main import main
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 25, in <module>
    from pip._internal.cli.progress_bars import BAR_TYPES
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/progress_bars.py", line 8, in <module>
    from pip._vendor.progress.bar import Bar, FillingCirclesBar, IncrementalBar
ModuleNotFoundError: No module named 'pip._vendor.progress'

Edit: after a reboot due to a free it now shows this (both pip and pip3 which previously showed the error above): WARNING: Skipping PyGObject as it is not installed. and rmlint --gui now returns:

Failed to load shredder: No module named 'shredder'
This might be due to a corrupted install; try reinstalling.

On another machine with almost the same setup/software and also using Wayland rmlint --gui runs fine.

cebtenzzre commented 2 years ago

Why do you have a pip installed at /usr/local/bin? Have you been running pip with sudo? At that point I don't know if any of your python packages can be trusted... But the shredder module should be provided by the rmlint-gui package; if PYTHONPATH=/usr/lib/python3/dist-packages python3 -c 'import shredder; shredder.run_gui()' does not work then there is something wrong with it. Maybe your setuptools got "updated" by pip too? pip uninstall setuptools to make sure. That might break python's ability to find system stuff (including the rmlint GUI) in dist-packages.

mYnDstrEAm commented 2 years ago

which pip returns /usr/local/bin/pip (same for pip3). I only ran sudo pip install -U youtube-dl as described here (and sudo pip3 uninstall mvt once recently).

That command doesn't work and returns the error of the issue.

How to check the setuptool?

cebtenzzre commented 2 years ago

Never run pip as root. youtube-dl is available via apt and the improved yt-dlp is too if you have bullseye-backports in your sources.list, but you can also install them with pip without sudo (optionally with --user) to put them in ~/.local, which works well if ~/.local/bin is on your PATH. pip could only be in /usr/local if you ran sudo pip3 install -U pip.

If pip3 show setuptools | grep Location shows anything other than /usr/lib/python3/dist-packages, you need to pip3 uninstall setuptools (or add sudo if it's anywhere else in /usr).

mYnDstrEAm commented 2 years ago

In that case I think its readme should be changed.

I'm currently having a complete bash history at least until around the time I noticed that the default HISTSIZE is too small (causing by-default notification-free unnecessary data-loss) and history | grep "sudo pip" doesn't show anything else.

I don't know why setuptools could be a problem and how to scan whether it's fine, like one can do with debsums or hashsums. If it's the location of it, which is /usr/local/lib/python3.6/site-packages I'm interested in why that would be a problem. For now I copied the files over and ran that command which however requires sudo. Uninstalling with sudo should okay or is it in any way possible that it's not? What to do after doing so? Isn't that package needed by something? And rmlint --gui still shows the same error. python-setuptools and python3-setuptools are still installed via apt, should these be uninstalled too?

cebtenzzre commented 2 years ago

I don't disagree that youtube-dl should not tell its users to run pip as root.

You must uninstall that copy of setuptools with sudo pip3 uninstall setuptools as it did not come from the Debian repos and is probably incompatible with the way python packages work on Debian. The version that comes with Debian is located in /usr/lib/python3/dist-packages/setuptools, dpkg-query -L python3-setuptools can tell you that. Keep the apt packages as they are the copies you want to keep, they are not the ones that got installed with sudo pip3.

mYnDstrEAm commented 2 years ago

Created an issue there ^

Please let me know if you have any ideas what (else) to try (or which logs to check) to solve this error; I'll comment if either of the two (that of the issue or Failed to load shredder: No module named 'shredder') disappears.

dirkf commented 2 years ago

I don't disagree that youtube-dl should not tell its users to run pip as root.

So how should a package be installed system-wide using pip? Not just a rhetorical point. Even if all my dealings with pip and its kin reinforce this perception, a pip solution may be the safest thing when the package is not available from an OS-specific package repository.

Please feel free to follow up at https://github.com/ytdl-org/youtube-dl/issues/30490.

cebtenzzre commented 2 years ago

If you have rmlint-gui installed, then /usr/lib/python3/dist-packages/shredder/__init__.py should exist and PYTHONPATH=/usr/lib/python3/dist-packages python3 -c 'import shredder; shredder.run_gui()' should 100% be able to import it. Did you somehow uninstall rmlint-gui or remove that file, or is your python installation/environment really that broken?

mYnDstrEAm commented 2 years ago

I didn't uninstall it before. I tried reinstalling it but the error still shows. Currently it says rmlint is already the newest version (2.9.0-2.3). One other thing I tried with python is the lutris-kodi addon (see the 54 there), I still have some youtube-dl folders copied elsewhere for later inspection in case that's useful and I'm using it with firejail since a while ago. I don't know what could have caused it as it works well on another machine. I'll try to find out how one could do some checks later, but if you have any ideas what else to try please let me know, there could very well be a trivial explanation for it. I just checked and I had this problem before.

cebtenzzre commented 2 years ago

I need you to actually verify a few things:

mYnDstrEAm commented 2 years ago
cebtenzzre commented 2 years ago

You have somehow installed python outside of your package manager (e.g. via sudo make install). That's the python3 everything is using, which doesn't know about dist-packages or the usual site-packages and won't work properly. sudo rm /usr/local/bin/python* should take care of that.

mYnDstrEAm commented 2 years ago

Great, thanks a lot, it works now.

It's really strange it got installed this way. Maybe I'll find out why later (most of the relatively few things I've built manually have also been built on the other computer where this problem didn't occur and I can't think of why it should get installed this way, especially as python should have already been installed).

cebtenzzre commented 2 years ago

Great! Feel free to close this issue.