我的问题是关于使用 Mac 终端运行一个简单的 mapit python 脚本来执行。
我正在关注“自动化无聊的东西”。我创建了一个脚本来从网站复制地址或使用剪贴板中的文本在谷歌地图上打开地图。请看下面的代码。
我尝试$ python /Users/.../mapit.py
使用命令行运行,但遇到以下错误消息:
Traceback (most recent call last):
File "/Users/.../mapit.py", line 2, in <module>
import webbrowser, sys, pyperclip
ImportError: No module named pyperclip
尽管在 IDLE shell 上成功运行了 pyperclip。
我已经使用终端重新安装了 pyperclip,并且我还从头开始重新编写了脚本。我在交互式 shell 中使用了 pyperclip,它正在工作。
有人可以帮我确定问题可能出在哪里吗?
映射脚本
#!/usr/bin/env pythonw
import webbrowser, sys, pyperclip
sys.argv
# Check if command line arguments were passed
if leng(sys.argv) > 1:
# we know that the address has been passed
address = ' '.join(sys.argv[1:])
else:
address = pyperclip.paste()
# https://www.google.ae/maps/place/<ADDRESS>
webbrowser.open('https://www.google.ae/maps/place/' + address)