python - 如何让 Automator 使用 pyperclip 识别 python 脚本?

标签 python macos shell anaconda automator

我正在 Mac OSX 10.12.3 中使用 Automator 来利用 pyperclip 运行 Python 脚本。 。我使用 Run Shell Script (/usr/bin/python) 创建了一个 Automator 步骤:

import pyperclip
import datetime
now = datetime.datetime.now()
pyperclip.copy(str(now.year) + str(now.month) + str(now.day) + '_' + str(now.hour) + str(now.minute) + str(now.second))

但是,它显示此错误:

ImportError: No module named pyperclip

我可以在终端中执行此代码,为什么 pyperclip 不被 /usr/bin/python 识别?仅供引用,我还安装了 Anaconda。

最佳答案

当我在 Anaconda virtualenv 下安装 pyperclip 时,Automator 正在使用 /usr/bin/python 。当我运行 python 时,我注意到它说:

Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:52:12) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

与 Automator 使用的版本相比,它看起来像是一个不同的 Python 版本。现在我要做的就是:

sudo /usr/bin/python -m pip install pyperclip

关于python - 如何让 Automator 使用 pyperclip 识别 python 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42056786/

相关文章:

python - 使用 ctypes 的回调(如何从 C 调用 python 函数)

python - Tensorflow 属性错误 : 'numpy.float32' object has no attribute 'value'

python - 如何使用Python将批量数据插入Cosmos DB?

python - 如何在python中设置程序标题

linux - 连接mongodb时选择数据库

python - 尽管导入操作系统,_get_batches_of_transformed_samples 中的 NameError : global name 'os' is not defined in keras_preprocessing/image/iterator. py

macos - 如何在 OSX 终端中获得滚动转换?

swift - 在 NSWindowController 上,设置 contentViewController 会更新窗口的位置,我该如何停止呢?

shell - 通过从属服务器上的Jenkins Shell清洁Docker容器

linux - awk 命令根据多个模式字符串提取特定字符串