ENH use pyperclip for read and to_clipboard
State: closed

Use [pyperclip](http://coffeeghost.net/src/pyperclip.py) to manage copy and pasting.

Fixes #3837, also cc #3845.


Labels:

Comments:
I've not yet tested myself on windows or linux (which should work with various things (not) installed).

Anyone mind having a try?

I did this from an x-window (linux), pasted to excel (where it is text)
did text-to-data
copied to clipboard
and repasted to ipython

pretty neat!

and a nice warning came up that I didn't have xclip installed

so maybe have some installation instructions in a warning 

I don't think there are any dependencies on windows, not sure about mac

so +1 on this

```
In [1]: DataFrame(randn(10,2),columns=list('AB')).to_clipboard()
/usr/bin/xclip

In [2]: pd.read_clipboard()
Out[2]: 
   Unnamed: 0         A         B
0           0 -0.782434 -1.592745
1           1 -0.679130  0.622381
2           2  0.407085 -1.429126
3           3 -1.210504 -0.012332
4           4 -0.665061  1.356827
5           5 -0.704815  0.274563
6           6 -1.406038  0.384197
7           7  0.637377 -0.397826
8           8 -1.627270  0.569159
9           9  1.120310 -0.324689

In [3]: x = pd.read_clipboard()

In [4]: x
Out[4]: 
   Unnamed: 0         A         B
0           0 -0.782434 -1.592745
1           1 -0.679130  0.622381
2           2  0.407085 -1.429126
3           3 -1.210504 -0.012332
4           4 -0.665061  1.356827
5           5 -0.704815  0.274563
6           6 -1.406038  0.384197
7           7  0.637377 -0.397826
8           8 -1.627270  0.569159
9           9  1.120310 -0.324689

In [5]: x.dtypes
Out[5]: 
Unnamed: 0      int64
A             float64
B             float64
dtype: object

```

and this is better than the old one...doesn't require gtk or tk (which if your linux is a server) doesn't normally install....xclip is good!

Hmmm but installation method for xclip may differ on different linuxes (can of worms?), tbh I think their message is pretty good. Works on mac, pretty sure it will work on Windows...

A good find of yours! Tagged for 0.11.1.

Also, I should update the docs before merging (I think the docstrings are now incorrect on the requirements, and something in RELEASE).

Just curious are there some **non trivial** use cases for reading and writing clipboard?

@nipunreddevil How _could_ copying and pasting be non-trivial...? :)

@jreback Do I need to add the license somewhere else?

umm...i think in the file is enough, you could copy it and put in a file in pandas/LICENSES though....I guess

@hayd just to play devils advocate >:) tmux copy-pasting to/from clipboard just _doesn't_ work with `xclip`.

@cpcloud That's not devil's advocate! If it doesn't work it's a problem... any workaround? preferring xsel?

Am I right in saying Windows no longer has any dependencies (It no longer needs python win32 extensions)?

yep `xsel` is the sol'n

@cpcloud it falls back on `xsel`, but that requires gtk/qt4 as well

oh well that is annoying (that `xsel` requires those libs). i haven't tried xclip + tmux in a server env mostly since i can just ssh in when i need to and do everything that way

@jreback So is this already dealt with in pyperclip? Or there is a ~~bug~~ regression with tmux? I'm lost.

I've put the license in and added docstring to generic.to_clipboard. Not sure if I have written dependencies correct for Windows (None?) and Linux.

no i was just commenting on the semi-non-trivial-ness of pasting with tmux...

this looks good

deps look fine too

mergable?

There's a silly typo, xlit, will add in those (two) characters and merge now...

and merge #3845 too thanks

related https://github.com/pydata/pandas/issues/3368