Terminal claims No pyperclip module Found but that I've already installed pyperclip?

本秂侑毒 提交于 2021-02-11 12:38:10

问题


So I'm new to learning Python and am trying to execute some Python code from Automate the Boring Stuff (specifically the Password Locker Project). In the book, it tells us to run this program (attached below) through Terminal, so I did the following steps:

  1. Saved the code in my home folder and titled it pw.py
  2. Changed the .py's files to make it executable by running chmod +x pw.py
  3. Tried to run my script by entering ./pw.py on Terminal

However when I run the code, Terminal says there is no module named pyperclip (again, shown below). Naturally, I tried to install pyperclip with the prompt python3.8 -m pip install pyperclip but Terminal claims that I've already installed pyperclip. Any ideas for how to solve this problem?

Here is the error I see on Terminal when I try to run my code Traceback (most recent call last): File "./pw.py", line 7, in <module> import sys, pyperclip ModuleNotFoundError: No module named 'pyperclip'

Here is the error I see on Terminal when I try to install pyperclip

Requirement already satisfied: pyperclip in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (1.8.0)

Here is the code I copied from Automate the Boring Stuff that I typed out on IDLE.


PASSWORDS = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6', 'blog': 'VmALvQyKAxiVH5G8v01if1MLZF3sdt', 'luggage': '12345'}

import sys, pyperclip
if len(sys.argv) < 2:
    print('Usage: py pw.py [account] - copy account password')
    sys.exit()

account = sys.argv[1] # first command line arg is the account name

if account in PASSWORDS:
    pyperclip.copy(PASSWORDS[account])
    print('Password for ' + account + ' copied to clipboard.')
else:
 print('There is no account named ' + account)

version: python3

Thanks!


回答1:


It sounds very much like you have more than one Python installation. You installed pyperclip with python3.8 specifically, but by executing your script using ./pw.py, you could be running it with some other installation currently set as your default. Try python3.8 pw.py and see if that works.

Edit: Glad that worked! If you'd like to investigate what version your system is using by default, try entering python --version on the command line. And as M Z mentioned below in a comment, sys.version_info (or also just sys.version) can access the current Python version from inside a script.



来源:https://stackoverflow.com/questions/63387372/terminal-claims-no-pyperclip-module-found-but-that-ive-already-installed-pyperc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!