0

I am currently having a problem because I cannot use the Win32clipboard library to retrieve the string that is in the clipboard in a variable on python. From what I understand, Win32clipboard is part of the pywin32 library. I managed to install pywin32 after quite a bit of difficulty. So I do import pywin32 at the start of my program. However, when I run my program, python gives me an error, "name 'win32clipboard' is not defined". So I do "import win32clipboard" but still get the same error. I really don't know how to do it. Thanks in advance.

Modification:

This is my code.

import pywin32
import win32clipboard
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
print (data)

and I get this error.

ModuleNotFoundError: No module named 'win32clipboard'

But when I write pip list in the CMD, I found pywin32. Screenshot CMD

I am using spyder 5.1.1 and Python 3.9 Thanks

  • did you import it? ```import win32clipboard```. Regarding how to use it can be found here – NeoTheNerd Dec 15 '21 at 13:38
  • yes I import win32clipboard but I have the error "No module named 'win32clipboard'" while I put the import and I also import pywin32 – Thomas Bravo Dec 15 '21 at 13:44
  • In Python normally the error occurs when trying to access a Python variable before initializing or defining it, with other plausible being misspelt the variable or function name, not defining a variable, trying to access a local variable. can you place a screen shot of the error, and you code, to help further? – NeoTheNerd Dec 15 '21 at 14:03
  • Did you install *PyWin32* correctly? https://stackoverflow.com/questions/58217869/how-to-install-pywin32-without-admin-rights/58217920#58217920. Also, please take a look at [\[SO\]: How to create a Minimal, Reproducible Example (reprex (mcve))](https://stackoverflow.com/help/minimal-reproducible-example). – CristiFati Dec 15 '21 at 14:46
  • I followed what you gave me to check if my installation of ppywin32 was good and I think it is because in all the manipulations I have done I always have the same message in the prompt control `Requirement already satisfied: pywin32 in c:\users\pilou\appdata\local\programs\python\python39\lib\site-packages (302)`. – Thomas Bravo Dec 15 '21 at 15:16
  • to get this message I used the command `C:\Users\pilou\AppData\Local\Programs\Python\Python39>python -m pip install --user pywin32` – Thomas Bravo Dec 15 '21 at 15:17
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 22 '21 at 13:32
  • I update the topic with more details – Thomas Bravo Dec 22 '21 at 20:53

1 Answers1

0

To use win32clipboard with python 3.9 or 3.10 you have to install the pywin32 library using:

pip install pywin32

after which your import line for win32clipboard will look something like this:

from win32 import win32clipboard
Oddaspa
  • 731
  • 5
  • 21
Coder
  • 1
  • 3