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

Can't copy on WSL2 #267

Open
cool-RR opened this issue Jun 30, 2024 · 2 comments
Open

Can't copy on WSL2 #267

cool-RR opened this issue Jun 30, 2024 · 2 comments

Comments

@cool-RR
Copy link

cool-RR commented Jun 30, 2024

➜  ~ pip freeze | grep pyperclip
pyperclip==1.9.0
➜  ~ python -m pyperclip -c hello
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/ramrachum/.local/lib/python3.10/site-packages/pyperclip/__main__.py", line 6, in <module>
    pyperclip.copy(sys.argv[2])
  File "/home/ramrachum/.local/lib/python3.10/site-packages/pyperclip/__init__.py", line 622, in lazy_load_stub_copy
    return copy(text)
  File "/home/ramrachum/.local/lib/python3.10/site-packages/pyperclip/__init__.py", line 469, in copy_wsl
    p = subprocess.Popen(['clip.exe'],
  File "/usr/lib/python3.10/subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1845, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'clip.exe'
@NikitaBeloglazov
Copy link

NikitaBeloglazov commented Jul 10, 2024

Please see #250
Clipman has support from Windows 10 LTSC (WSL1) to the latest Windows 11 (WSL2)

@edward-jazzhands
Copy link

So I've looked into this after having the same problem and realized that the issue is that pyperclip is built to detect WSL1. But it does not detect WSL2, and treats them as being the same thing. There is only a single init_wsl_clipboard function. WSL1 has access to windows utilities whereas WSL2 does not. That's why it's looking for clip.exe. I'm guessing it was written before WSL2 was a thing and support was never added.

The pyperclip solution is that you can manually detect WSL2 in your program and then set pyperclip to use xclip. But a better solution might just be to use Clipman instead since its being actively maintained.

It would be nice to see an update to pyperclip to add WSL2 support though.

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

3 participants