我在Mac上运行Python。
我有以下代码:
import shelve, pyperclip, sys
mcbShelf = shelve.open('mcb')
#Save clipboard content
if len(sys.argv) == 3 and sys.argv[1].lower() == 'save':
mcbShelf[sys.argv[2]] = pyperclip.paste
elif len(sys.argv) == 2:
#List keywords and load content
if sys.argv[1].lower() == 'list':
pyperclip.copy(str(list(mcbShelf.keys())))
elif sys.argv[1] in mcbShelf:
pyperclip.copy(mcbShelf[sys.argv[1]])
mcbShelf.close()
但是,当我运行文件时,出现以下错误:
回溯(最近通话最近): 文件“ ./mcb.py”,第7行,在 导入搁置,pyperclip,sys ModuleNotFoundError:没有名为“ pyperclip”的模块
我已经通过pip install安装了pyperclip。
当我搜索此问题时,出现的一件事是安装了多个版本的python,并且pip将模块安装到与运行文件时使用的python版本不同的版本。 Modules are installed using pip on OSX but not found when importing
我想知道如何检查pip install在哪里安装模块,更重要的是如何检查我正在使用的python版本。
运行which -a pip
会得到:
/ Users / stephenlang / anaconda / bin / pip
运行which -a python
后,我得到:
/用户/ stephenlang / anaconda / bin / python
/ usr / bin / python
有没有一种方法可以轻松地将pip安装与正确的python版本对齐?