简体   繁体   English

Pyperclip-无模块| 自动化无聊的东西

[英]Pyperclip - no module | Automate the boring stuff

My question is about running a simple mapit python script using the Mac terminal to execute. 我的问题是关于使用Mac终端执行简单的mapit python脚本来执行。

I am following along with 'Automate the boring stuff'. 我跟随“自动化无聊的东西”。 I created a script to copy an address either from a website or using text in the clipboard to open a map on google maps. 我创建了一个脚本,可以从网站复制地址,也可以使用剪贴板中的文本在Google地图上打开地图。 Please see code below. 请参见下面的代码。

I have tried to run $ python /Users/.../mapit.py using the command line but I am encountering the following error message: 我试图使用命令行运行$ 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

Despite successfully running pyperclip on the IDLE shell. 尽管在IDLE shell上成功运行了pyperclip。

I have reinstalled pyperclip using terminal and I have also re-written the script from scratch. 我已经使用终端重新安装了pyperclip,并且还从头开始重新编写了脚本。 I have used pyperclip in the interactive shell and it is working. 我在交互式外壳中使用了pyperclip,它正在工作。

Could someone please help me identify where the problem might be? 有人可以帮我找出问题所在吗?

MAPIT SCRIPT 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)

Ah, you might want to consider reformulating the title of your question as it is a little misleading as to your problem. 嗯,您可能要考虑重新编写问题的标题,因为这对您的问题有些误导。

However, regarding the failure to find the right module it's important to mention how you (re-)installed it: 但是,关于找不到正确的模块的问题,重要的是要提到您如何 (重新)安装它:

My guess, given that you are on a Mac, is that you have multiple versions of python installed (eg the native python that is part of macOS and a version by Homebrew or another package manager). 考虑到您在Mac上,我的猜测是您安装了多个版本的python (例如,macOS的本机python和Homebrew或其他软件包管理器的版本)。 You are most likely installing the module in one of them, while trying to run your code with the other. 您最有可能在其中一个模块中安装模块,同时尝试与另一个模块一起运行代码。

I am guessing this answer might help you out. 我猜这个答案可能会帮助您。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM