Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
896 views
in Technique[技术] by (71.8m points)

python - Terminal shows “ImportError: No module named pyperclip"

I was writing a code in which the user would run a python program on the Terminal ( I am using OSX ) and the program would copy the username’s password to the clipboard.

Here’s the code:

import sys
import pyperclip

passwords={'AaruDon':'zxcvbnasdjl@!#@!#4324(3’,’Sandy’:’qjljeqkjleq’} # AaruDon and Sandy are usernames that the user might input in the Terminal

idd=sys.argv[1] # idd would be the username that the user will put in the terminal while he is opening the program

if str(sys.argv[1])in passwords.keys():
  pyperclip.copy(str(passwords[idd]))

  print(' The password has been copied to the clipboard')

else:
  print('Sorry. There is no such username.')

When I run this program I get:

ImportError: No module named pyperclip

Believe me, I have imported pyperclip in some older program before and it did work! I don’t know why is it throwing this error if I try to run this from the Terminal!

How do I get rid of this?

NOTE: Pyperclip is installed. I have checked it before too

EDIT 1) I ran another program in the Terminal which also used pyperclip and it did work! The problem is with this program only

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

See here: https://inventwithpython.com/hacking/chapter2.html

I had the same problem. Download it and put in the same dir as your script.

https://inventwithpython.com/pyperclip.py


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...