【问题标题】:Pyperclip - no module | Automate the boring stuffPyperclip - 无模块 |自动化无聊的东西
【发布时间】:2018-09-22 04:54:06
【问题描述】:

我的问题是关于使用 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)

【问题讨论】:

    标签: python bash macos terminal pyperclip


    【解决方案1】:

    啊,您可能需要考虑重新制定问题的标题,因为它对您的问题有点误导。

    但是,关于未能找到正确的模块,重要的是要提及您是如何(重新)安装它的:

    鉴于您使用的是 Mac,我的猜测是您安装了多个 python 版本(例如,作为 macOS 一部分的本机 python 和 Homebrew 或其他包管理器的版本) .您很可能将模块安装在其中一个中,同时尝试与另一个一起运行您的代码。

    我猜this 的答案可能会对您有所帮助。

    祝你好运!

    【讨论】:

    • 谢谢!我最终重新安装了整个东西,它工作得很好。
    猜你喜欢
    • 2020-05-14
    • 2019-10-18
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    相关资源
    最近更新 更多