Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
894 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...