【问题标题】:importError in Automator while running Python 3 script in shell /bin/bash在 shell /bin/bash 中运行 Python 3 脚本时 Automator 中的 importError
【发布时间】:2020-10-05 18:07:13
【问题描述】:

我正在尝试使用 shell /bin/bash 将我的 python3 脚本添加到 Automator,但不断收到错误:

"ImportError: No module named watchdog.observers”"

我假设是因为它运行 Python 2 而不是 3。在互联网上搜索后,我想出了以下 ./bash_profile 和 shebang 行,但它似乎仍然不起作用。这就是我在自动机中厌倦的:

这就是我的 bash_profile 的样子:

最后这就是 Python 脚本中的第一行的样子:

然后当我运行 Automator 时,我收到以下错误消息:

为什么会出现导入错误以及如何解决?

【问题讨论】:

    标签: python python-3.x macos automation importerror


    【解决方案1】:

    好的,我解决它。在 Automator (shell /bin/bash) 中我做了:

    /Users/username/Documents/categorize_downloads.py
    

    在此之前,我对要运行的文件具有更改权限,因此:

    chmod 755 filename
    

    最后我把shebang改成:

    #!/usr/local/bin/python3
    

    似乎可以使用“env python3”代替,但在这种情况下,我必须删除“env”。

    【讨论】:

      猜你喜欢
      • 2021-05-11
      • 1970-01-01
      • 2014-09-29
      • 2018-04-17
      • 2016-02-29
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多