【问题标题】:Terminal shows “ImportError: No module named pyperclip"终端显示“ImportError: No module named pyperclip”
【发布时间】:2017-12-16 21:54:44
【问题描述】:

我正在编写一个代码,用户将在终端上运行一个 python 程序(我使用的是 OSX),该程序会将用户名的密码复制到剪贴板。

代码如下:

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.')

当我运行这个程序时,我得到:

ImportError: 没有名为 pyperclip 的模块

相信我,我之前在一些旧程序中导入了 pyperclip,它确实有效!如果我尝试从终端运行它,我不知道为什么会抛出这个错误!

我该如何摆脱它?

注意:Pyperclip 已安装。我也查过

编辑 1)我在终端中运行了另一个程序,它也使用了 pyperclip,它确实有效!问题只出在这个程序上

【问题讨论】:

  • @DavidG 已经安装了
  • 试试pip install pyperclip,看看你得到什么消息,然后你应该检查你是否安装了不同版本的python,你正在使用哪个版本运行这个脚本,以及这个版本是否可以访问pyperclip
  • @Dadep 已经安装了
  • 你检查过它在你的PYTHONPATH吗?
  • 也许你已经为一个版本的 Python 安装了它,但是从终端运行时你使用的是另一个没有安装它的版本。

标签: python macos python-3.x terminal python-3.6


【解决方案1】:

请看这里:https://inventwithpython.com/hacking/chapter2.html

我遇到了同样的问题。下载它并放在与您的脚本相同的目录中。

https://inventwithpython.com/pyperclip.py

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-10
    • 2012-08-12
    • 2011-10-19
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    相关资源
    最近更新 更多