[Tutor] pandas.to_clipboard() copies nothing

boB Stepp robertvstepp at gmail.com
Sat Jun 6 15:13:10 EDT 2020


On Sat, Jun 6, 2020 at 1:40 PM Peter Otten <__peter__ at web.de> wrote:
>
> Jim wrote:
>
> > On 6/6/20 4:25 AM, Peter Otten wrote:
> >> Jim wrote:
> >>
> >>> Mint18.3, python3.6, pandas 0.24.1
> >>>
> >>>
> >>> et_file = '/home/jfb/Downloads/PortfolioDownload.csv'
> >>> df = pd.read_csv(et_file, header=6, usecols=[0, 7], skipfooter=6,
> >>> engine='python')
> >>> df.to_clipboard(sep=',')
> >>> print(df)
> >>>
> >>> Manual notes the following. I'm not using PyQt4, but xclip is installed.
> >>>
> >>> Notes: Requirements for your platform.
> >>>
> >>>       Linux : xclip, or xsel (with PyQt4 modules)
> >>>       Windows : none
> >>>       OS X : none

> > To sum up. If I run it from the python console it give an error, but
> > copies to the clipboard. If I run the python file from the terminal it
> > gives an error and does not copy to the clipboard.
>
> Most of your errors seem to be warnings.
>
> Looking into the code writing to the clipboard shows that it requires the
> DISPLAY environment variable to be set, so I'd check that in the terminal.
>
> https://github.com/pandas-dev/pandas/blob/master/pandas/io/clipboard/__init__.py#L539
>
> shows that
>
>     if HAS_DISPLAY:
>         if _executable_exists("xsel"):
>             return init_xsel_clipboard()
>         if _executable_exists("xclip"):
>             return init_xclip_clipboard()
>         if _executable_exists("klipper") and _executable_exists("qdbus"):
>             return init_klipper_clipboard()
>         ... [try qt]
>
> QT is the last option. From that we can conclude that xclip is not found.
> Maybe you can fix that by adjusting the path.
> Or you try to set the clipboard mechanism explicitly with
>
> pandas.io.clipboard.set_clipboard("xclip")

I don't know if this is relevant or not, but when I installed Neovim
on my PC I found that I could not access the system clipboard from
within Neovim.  Investigation discovered that xsel was not installed.
Like Jim I am using Linux Mint.  Once I installed xsel those problems
went away.  I cannot recall if I had to do any special configurations
for xsel or not.



-- 
boB


More information about the Tutor mailing list