asweigart / pyperclip

Python module for cross-platform clipboard functions.
https://pypi.python.org/pypi/pyperclip
BSD 3-Clause "New" or "Revised" License
1.65k stars 196 forks source link

xclip installed but: Pyperclip could not find a copy/paste mechanism for your system #259

Open nick-youngblut opened 6 months ago

nick-youngblut commented 6 months ago

I'm using Debian GNU/Linux 12 (FROM python:3.9-slim-buster), and have xclip installed.

However, in my streamlit app, I'm still getting the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/pyperclip/__init__.py", line 659, in lazy_load_stub_copy
    return copy(text)
  File "/usr/local/lib/python3.9/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'm using pyperclip==1.8.2

My dockerfile:

# Use an official Python runtime as a base image
FROM python:3.9-slim-buster

# Set the working directory in the container
WORKDIR /app

# Install system dependencies
RUN apt-get update \
    && apt-get install -y git xclip \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Copy the requirements.txt file into the container
COPY requirements.txt .

# Install Python dependencies
RUN pip3 install -r requirements.txt

# Copy the app files into the container
COPY bridge_rna_designer/ ./bridge_rna_designer/
COPY .streamlit/ ./.streamlit/
COPY img/ ./img/
COPY app.py ./

# Make port ${PORT} available to the world outside this container
EXPOSE ${PORT}

# Run the app when the container launches
CMD sh -c "streamlit run app.py \
  --server.headless true \
  --server.fileWatcherType none \
  --browser.gatherUsageStats false \
  --server.port=${PORT} \
  --server.address=0.0.0.0"

My requirements.txt file:

biopython==1.83
click==7.0
python-dotenv==1.0.0
streamlit==1.31.1
pyperclip==1.8.2

The relevant streamlit code is basically the same at shown in https://discuss.streamlit.io/t/how-to-add-copy-to-clipboard-button-to-text-area/49648/2.

nick-youngblut commented 6 months ago

@asweigart the docs state:

pip install gtk to install the gtk Python module.

...but does the gtk package still exist on pypi? I can't find it.

The same goes for PyQt4. I only see PyQt5 and PyQt6.

nick-youngblut commented 5 months ago

@asweigart should this repo be considered a public archive, since it has not been updated in 3 years?

Nagasaki45 commented 3 months ago

I had a similar issue the other day when using pyperclip in GitHub Actions. The issue was solved by using Xvfb. If my understanding is correct, while xclip and the other copy/paste mechanisms provide the ability to copy and paste from the clipboard, the clipboard itself is provided by X, which Xvfb emulates. In my case the solution was something like this:

sudo apt-get -y install xvfb
xvfb-run pytest