Pyperclip - 没有模块 |自动化无聊的事情
Pyperclip - no module | Automate the boring stuff
我的问题是关于 运行使用 Mac 终端执行一个简单的 mapit python 脚本。
我跟着 'Automate the boring stuff'。我创建了一个脚本来从网站复制地址或使用剪贴板中的文本在 google 地图上打开地图。请看下面的代码。
我已尝试使用命令行 运行 $ 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 上安装了 pyperclip shell。
我已经使用终端重新安装了 pyperclip,并且还从头开始重写了脚本。我在交互式 shell 中使用了 pyperclip,它正在工作。
有人可以帮我确定问题出在哪里吗?
MAPIT 脚本
#!/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)
啊,您可能需要考虑重新表述问题的标题,因为它对您的问题有点误导。
但是,关于未能找到正确的模块,重要的是要提及您是如何(重新)安装它的:
鉴于您使用的是 Mac,我的猜测是您安装了 多个版本的 python(例如本机 python 是 macOS 的一部分,是 Homebrew 或其他包管理器的版本)。您很可能在其中一个中安装了模块,同时尝试 运行 您的代码与另一个。
我猜 this 回答可能会对您有所帮助。
祝你好运!
我的问题是关于 运行使用 Mac 终端执行一个简单的 mapit python 脚本。
我跟着 'Automate the boring stuff'。我创建了一个脚本来从网站复制地址或使用剪贴板中的文本在 google 地图上打开地图。请看下面的代码。
我已尝试使用命令行 运行 $ 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 上安装了 pyperclip shell。
我已经使用终端重新安装了 pyperclip,并且还从头开始重写了脚本。我在交互式 shell 中使用了 pyperclip,它正在工作。
有人可以帮我确定问题出在哪里吗?
MAPIT 脚本
#!/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)
啊,您可能需要考虑重新表述问题的标题,因为它对您的问题有点误导。
但是,关于未能找到正确的模块,重要的是要提及您是如何(重新)安装它的:
鉴于您使用的是 Mac,我的猜测是您安装了 多个版本的 python(例如本机 python 是 macOS 的一部分,是 Homebrew 或其他包管理器的版本)。您很可能在其中一个中安装了模块,同时尝试 运行 您的代码与另一个。
我猜 this 回答可能会对您有所帮助。
祝你好运!