0

I recently shifted to a Macbook. I installed Python 3.8 and installed Pyperclip using pip install pyperclip in the terminal, which was successful. When I tried to import it in IDLE shell, I get the error

ModuleNotFoundError: No module named 'pyperclip'.


On looking around I found that pyperclip has been installed in-

/Users/aamodpant/Library/Python/2.7/lib/python/site-packages/pyperclip

I did not install Python 2.7 but it must be required for macOS, so I don't want to delete it. How do I change the "default" version of Python for installing new libraries?

Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
Aamod Pant
  • 21
  • 4

2 Answers2

0

You can reinstall or upgrade pyperclip using sudo:

pip3 install -U pyperclip

Also, run your script using python3 instead of just python:

python3 script.py

The best is to use alias, as this answer describes changing default Python version in Mac can cause multiple issues.

alias python=python3
alias pip=pip3

The answer you are probably looking for is You should not change this.

Otherwise, you may like to set Python 3 as default, there are many ways to do it. But do it with caution as the guides suggest below.

The official documentation: Using Python on a Macintosh, some well described very good guides: The right and wrong way to set Python 3 as default on a Mac, Installing Python 3 on Mac OS X.

Mrinal Roy
  • 969
  • 7
  • 12
  • 1
    **NEVER** encourage the use of `sudo pip`. It is a security risk to use root privileges with pip to install Python. If someone puts a malicious project on PyPI and it's the installed with sudo, you give an attacker **root** access to your machine (see here https://stackoverflow.com/a/21056000/486919) – ZWang Jul 22 '20 at 09:33
0

Use :

python3 -m pip install pyperclip

This will install the package for python3.

Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40