0

Goal: copy a string to clipboard using Python on Android Linux 11

I tried pyperclip but it doesn't work on Linux yet.

import pyperclip
pyperclip.copy("Hello World")

Error:

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
    start(fakepyfile,mainpyfile)
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
    exec(open(mainpyfile).read(),  __main__.__dict__)
  File "<string>", line 3, in <module>
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pyperclip/__init__.py", line 659, in lazy_load_stub_copy
    return copy(text)
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pyperclip/__init__.py", line 336, in __call__
    raise PyperclipException(EXCEPT_MSG)
pyperclip.PyperclipException:
    Pyperclip could not find a copy/paste mechanism for your system.
    For more information, please visit https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error

I also tried pandas but it didn't work too (code from https://stackoverflow.com/a/41191377/15754341)

import pandas as pd
df = pd.DataFrame("Hello World")
df.to_clipboard(index = False, header = False)

Error:

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
    start(fakepyfile,mainpyfile)
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
    exec(open(mainpyfile).read(),  __main__.__dict__)
  File "<string>", line 3, in <module>
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pandas/core/generic.py", line 2785, in to_clipboard
    clipboards.to_clipboard(self, excel=excel, sep=sep, **kwargs)
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pandas/io/clipboards.py", line 123, in to_clipboard
    clipboard_set(text)
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pandas/io/clipboard/__init__.py", line 627, in lazy_load_stub_copy
    copy, paste = determine_clipboard()
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pandas/io/clipboard/__init__.py", line 525, in determine_clipboard
    with open("/proc/version", "r") as f:
PermissionError: [Errno 13] Permission denied: '/proc/version'

Question: Is there a universal method to copy a string to clipboard that would work on any operating system and device?

Mat
  • 202,337
  • 40
  • 393
  • 406
adzhanoev
  • 26
  • 1
  • 5
  • `pyperclip` does work with Linux. The docs say: On Linux, this module makes use of the `xclip` or `xsel` commands, which should come with the os. Otherwise run “sudo apt-get install xclip” or “sudo apt-get install xsel” (Note: `xsel` does not always seem to work.) Otherwise on Linux, you will need the gtk or PyQt4 modules installed. – BoarGules Aug 16 '21 at 21:05
  • That pyperclip is supposed to do exactly what you are asking for and apparently does not quite manage it is an indication that it is probably not fully possible to do. – khelwood Aug 16 '21 at 21:07
  • Maybe [Copying from clipboard using tkinter without displaying window](https://stackoverflow.com/q/24559675/355230) and `tkinter` in now part of the Python standard library. – martineau Aug 16 '21 at 22:07

0 Answers0