timbertson / pyperclip

improved fork of coffeeghost's `pyperclip` module
http://coffeeghost.net/2010/10/09/pyperclip-a-cross-platform-clipboard-module-for-python/comment-page-1/
9 stars 3 forks source link

Question #4

Open pauloney opened 1 month ago

pauloney commented 1 month ago

I am trying to use a module (PyDeTeX) that tests to see if pyperclip is installed:

        # Check if pyperclip is enabled
        self._clip = True
        try:
            pyperclip.paste()
        except pyperclip.PyperclipException:
            self._clip = False
            error = 'pyperclip is not available on your system (copy/paste mechanism). GUI buttons were disabled'
            warn(error)
            self._process_clip_button['state'] = tk.DISABLED
            self._copy_clip_button['state'] = tk.DISABLED

and it fails the test, even though I have pyperclip installed.

Are you able to help me understand what is going on?

timbertson commented 1 month ago

What error does it log?

pauloney commented 1 month ago

The error that it logs is exactly what is written on the piece of code above:

$ python3 -m pydetex.gui
/usr/local/lib/python3.8/dist-packages/pydetex/gui.py:246: UserWarning: pyperclip is not available on your system (copy/paste mechanism). GUI buttons were disabled
  warn(error)

Line 246 is the line of warn(error).

Is this the correct way to test for pyperclip installation?

pauloney commented 1 month ago

It seems, at least on Ubuntu 22.04, that the lines above expects pyperclip to be found on /usr/local/lib/python3/dist-packages/pyperclip and in reality it is installed on /usr/local/lib/python3.8/dist-packages/pyperclip

and a simple symlink does not seem to solve the problem.

timbertson commented 1 month ago

Ah whoops, I misread and assumed the warn(error) was logging the error was caught by this line: except pyperclip.PyperclipException.

Without logging the actual error that was raised it could be anything, no way to guess 🤷