How to copy to clipboard in python

In my python app I am trying to use: pyperclip to handle copy/paste clipboard, which works on Mac but not Linux based on what I see in the logs. Pyperclip mentions:
sudo apt-get install xclip to install the xclip utility. … but I can’t do that in Shell.

Also, I tried this in my render.yaml:
services:

a Docker web service

  • type: web
    name: keypoints
    runtime: python
    plan: starter
    autoDeploy: true
    buildCommand: |
    apt-get update && apt-get install -y xclip
    pip install -r requirements.txt
    startCommand: uvicorn main:app --workers 1 --host 0.0.0.0 --port $PORT
    … but it was not installed

… i’m seeing:
File “/opt/render/project/src/keys2text.py”, line 1066, in copy_chat

Dec 18 03:58:08 PM pyperclip.copy(text_without_markdown_and_content_paste)

Dec 18 03:58:08 PM File “/opt/render/project/src/.venv/lib/python3.11/site-packages/pyperclip/init.py”, line 622, in lazy_load_stub_copy

Dec 18 03:58:08 PM return copy(text)

Dec 18 03:58:08 PM ^^^^^^^^^^

Dec 18 03:58:08 PM File “/opt/render/project/src/.venv/lib/python3.11/site-packages/pyperclip/init.py”, line 295, in call

Dec 18 03:58:08 PM raise PyperclipException(‘Pyperclip could not find a copy/paste mechanism for your system. For more information, please visit Welcome to Pyperclip’s documentation! — Pyperclip 1.5 documentation’ + additionalInfo)

Dec 18 03:58:08 PMpyperclip.PyperclipException: Pyperclip could not find a copy/paste mechanism for your system. For more information, please visit Welcome to Pyperclip’s documentation! — Pyperclip 1.5 documentation

Dec 18 03:58:08 PMOn Linux, you can run sudo apt-get install xclip or sudo apt-get install xselect to install a copy/paste mechanism.

Otherwise the app works perfect, just no clipboard.

Ideas or options ?

2 Likes

I will just code some javascript, perhaps that’s a better solution.