Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use it with Docker #161

Closed
joaogabrielzo opened this issue Dec 21, 2019 · 10 comments
Closed

Cannot use it with Docker #161

joaogabrielzo opened this issue Dec 21, 2019 · 10 comments

Comments

@joaogabrielzo
Copy link

I tried to Dockerize my application and everytime I get "Pyperclip could not find a copy/paste mechanism for your system."

I have tried installing xclip, xsel and the Python packages that might be needed, but I still be getting this error.

I tried using ubuntu:18.04 base image.

@loopinf
Copy link

loopinf commented Jun 28, 2020

Same behavior with me.

@ra100
Copy link

ra100 commented Jul 5, 2020

Seems we have the same/similar issue, we're using pyperclip with RobotFramework, using just pyperclip.copy(text) and pyperclip.paste() and when we run it locally, it works fine. But inside the docker we always get empty string from the clipboard.

@lovelytxm
Copy link

This also happens with me. i try to run robotframework on Docker. but this pyperclip is not work.

@merwok
Copy link

merwok commented Apr 25, 2022

It’s not just about the program used to access the clipboard, but sharing the system resources that are accessed by these programs to work with clipboard.

@lovelytxm
Copy link

lovelytxm commented Apr 29, 2022

Hi,
I fixed the issue now. need to simulate a display in docker. It works well.
steps:

  1. apt-get install xvfb
  2. apt-get install xclip
  3. set a display
    a. /# Xvfb :99 -screen 0 1280x720x16 &
    b. /# export DISPLAY=:99

@rightx2
Copy link

rightx2 commented Dec 21, 2022

I've tried but using pyperclip failed...

Below is part of my Dockerfile

...
RUN apt-get install -y xclip xvfb
RUN Xvfb :99 -screen 0 1280x720x16 &
RUN export DISPLAY=:99

Did I miss something?

@merwok
Copy link

merwok commented Dec 21, 2022

yes, xvfb creates a fake X context so that X programs can work. it’s not the same as giving access to the host X server.

@rightx2
Copy link

rightx2 commented Dec 21, 2022

@merwok Could you explain more?.. .. and I'd like to know how can I solve this in docker..

@merwok
Copy link

merwok commented Dec 22, 2022

this isn’t the place to explain how X clients connect to the X server, but here are examples of docker containers and run commands for graphical apps: https://blog.jessfraz.com/post/docker-containers-on-the-desktop/#guis

@caarmen
Copy link

caarmen commented Sep 21, 2023

I've tried but using pyperclip failed...

Below is part of my Dockerfile

...
RUN apt-get install -y xclip xvfb
RUN Xvfb :99 -screen 0 1280x720x16 &
RUN export DISPLAY=:99

Did I miss something?

I tried this and it worked for my use case:

RUN apt-get install -y xclip xvfb
ENV DISPLAY=:99
RUN nohup bash -c "Xvfb :99 -screen 0 1280x720x16 &"

The nohup command may not be best practice though. But it worked 😅

UPDATE:

This seems to work to make pyperclip.copy("text") not raise an exception.

However, reading from the clipboad (pyperclip.paste()) after the copy returns an empty string.

And there's a warning seen in logs: Error: Can't open display: :99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants