Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: When using gi.repository you must not import static modules like "gobject". #106

Open
coreycb opened this issue Oct 16, 2017 · 2 comments

Comments

@coreycb
Copy link

coreycb commented Oct 16, 2017

When using pyperclip in Ubuntu Artful, we are hitting the following AttributeError from pygobject:

AttributeError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183

For a much more detailed explanation and debug please see:
https://bugs.launchpad.net/ubuntu/+source/python-pyperclip/+bug/1722553

To reproduced this on Ubuntu Artful all you need to do is:

#!/usr/bin/env python
import keyring # imports gi
import pyperclip # imports gtk
pyperclip.paste()

Narrowing down a bit more, this can also be reproduced with the following python script:

#!/usr/bin/env python
import gtk
import gi

The 2 lines of code that appear to be conflicting are:

  1. /usr/lib/python2.7/dist-packages/keyrings/alt/Gnome.py
    import gi
  2. /usr/lib/python2.7/dist-packages/pyperclip/clipboards.py
    import gtk

And if I understand correctly from https://bugzilla.gnome.org/show_bug.cgi?id=709183, this is importing gtk+2 modules via 'import gtk' as well as gtk+3 modules via 'import gi' which causes module conflicts (according to the same bug).

From http://www.pygtk.org/: Note: New users are encouraged to use GTK+3 through the PyGObject bindings instead of using PyGTK with GTK+2.

So it seems to me that pyperclip in artful needs to move to GTK+3. Artful is set to release this week, but we can still backport a patch from upstream post release as a stable release update.

@coreycb
Copy link
Author

coreycb commented Nov 17, 2017

I think this is mainly what needs to be done to move to GTK+3 (and also remove import gtk from cmd2).

def init_gtk_clipboard():
    from gi.repository import Gtk, Gdk

    def copy_gtk(text):
        global cb
        cb = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        cb.set_text(text, -1)
        cb.store()

    def paste_gtk():
        clipboardContents = gtk.Clipboard().wait_for_text()
        # for python 2, returns None if the clipboard is blank.
        if clipboardContents is None:
            return ''
        else:
            return clipboardContents

@gruns
Copy link

gruns commented Jul 11, 2020

Also encountering this bug.

AttributeError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183

Linux Mint v18.2.

living180 added a commit to living180/upass that referenced this issue Dec 5, 2023
pyperclip is abandoned upstream and is broken with GTK3 [1].  Switch to
using pyclip instead.

[1] asweigart/pyperclip#106

Signed-off-by: Daniel Harding <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants