Chris Ray
Chris Ray

Reputation: 303

Pyperclip: "When using gi.repository you must not import static modules like "gobject"

I am making a program that will allow my phone to share its clipboard with my PC. I am using Pyperclip as it appears to be the easiest and most cross-platform solution. However, when I run the code below:

...
elif "incoming_clipboard:" in server_command:
    print(server_command)
    pyperclip.copy(server_command.replace("incoming_clipboard: ", ""))
...

I get the error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/home/chris/Documents/Programming/Synchrony/Desktop/Phone.py", line 30, in do_sync
    self.handle_commands(bluetooth_socket)
  File "/home/chris/Documents/Programming/Synchrony/Desktop/Phone.py", line 65, in handle_commands
    pyperclip.copy(server_command.replace("incoming_clipboard: ", ""))
  File "/usr/lib/python3.9/site-packages/pyperclip/__init__.py", line 659, in lazy_load_stub_copy
    return copy(text)
  File "/usr/lib/python3.9/site-packages/pyperclip/__init__.py", line 158, in copy_gtk
    cb = gtk.Clipboard()
  File "/usr/lib/python3.9/site-packages/gi/__init__.py", line 69, in __getattr__
    raise AttributeError(_static_binding_error)
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

I know its not due to the string being invalid or anything, because 1) I am explicitly converting it from bytes to a string, and 2) it prints perfectly fine. I don't know if this is relevant, but I am using Linux, so perhaps that is affecting Pyperclip? Do you guys have any solutions?

Upvotes: 2

Views: 878

Answers (1)

Chris Ray
Chris Ray

Reputation: 303

https://github.com/dynobo/normcap/issues/100

After going to the Github page for PyperClip, I found a similar issue that someone else had that suggested switching to PyClip. After installing PyClip and implementing it in project, I can confirm that it works perfectly without any issues.

Upvotes: 3

Related Questions