2

I've been trying to learn python using Automate the Boring Stuff with Python (has not been as easy as I would have liked). In chapter 6, the author is using a module he created for a project. I seemingly installed the module successfully, but I'm getting the following error when I run his sample code:

import pyperclip
pyperclip.copy('Hello, world!')
pyperclip.paste()


Traceback (most recent call last):
  File "C:\Users\16463\OneDrive\Desktop\test.py", line 1, in <module>
    import pyperclip
ModuleNotFoundError: No module named 'pyperclip'

I'm using Thonny IDE.

Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58
Mil13
  • 25
  • 4

4 Answers4

1

Look at Update #1 below for the answer.


You need to install the pyperclip module before using it.

In your terminal, execute the following command to install pyperclip.

pip install pyperclip

Reference:


UPDATE #1

I see that in one of your comments you said that you are using Thonny IDE.

You can install packages in Thonny IDE from Tools -> Manage Packages. There you can search for required packages and install them.

Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58
  • i did that already, just did it again and got the following msg: Requirement already satisfied: pyperclip in c:\users\16463\python\python37-32\lib\site-packages (1.8.0) – Mil13 Aug 13 '20 at 15:48
  • @shlobb13 Did you try it from *Manage Packages* also? – Bilesh Ganguly Aug 13 '20 at 15:50
0

The error: No module named 'pyperclip', means the module is not installed correctly.

You can find more details of how to install third party module in Appendix A of the book.

I installed pyperclip successfully by typing "pip install --user pyperclip" in cmd, you can give it a try.

Ryan-Rguo
  • 31
  • 2
  • i did that already, just did it again and got the following msg: Requirement already satisfied: pyperclip in c:\users\16463\python\python37-32\lib\site-packages (1.8.0) – Mil13 Aug 13 '20 at 15:48
0

First, make sure you only use a single version of Python, preferably the latest. It's possible that you have multiple versions installed and are using one for which the module was not installed.

I seemingly installed the module successfully

To test this, let's get the list of third-party packages you have installed. open a command line and run pip freeze -l. Make sure pyperclip is indeed on the list.

  • If it isn't on the list, try installing again (with pip install pyperclip).

    • If installation is confirmed to be successful, try using it again and it should work!
    • If installation fails, add the error message to the question and we'll see :)
  • If it is on the list and yet you are getting ModuleNotFoundError, make sure pyperclip is spelled correctly. It could be the case that you had a typo during installation with pip, and installed, say, pyperclkp instead.

pitamer
  • 905
  • 3
  • 15
  • 27
0

Thonny uses its own Python interpreter by default. Unless you have changed the interpreter (Run => Select interpreter), Thonny's Python doesn't use c:\users\16463\python\python37-32\lib\site-packages

You should either install pyperclip to Thonny's bundled Python ("Tools => Manage packages" or "Tools => Open system shell") or make Thonny use your other Python ("Run => Select interpreter")

Aivar
  • 6,814
  • 5
  • 46
  • 78