[英]importError in Automator while running Python 3 script in shell /bin/bash
I'm trying to add my python3 script to Automator using the shell /bin/bash, but keep getting the error:我正在尝试使用 shell /bin/bash 将我的 python3 脚本添加到 Automator,但不断收到错误消息:
"ImportError: No module named watchdog.observers”"
Which I assume is because it runs Python 2 and not 3. After searching on the internet I came up with the following./bash_profile and shebang line, but it still does not seem to work.我认为这是因为它运行 Python 2 而不是 3。在互联网上搜索后,我想出了以下./bash_profile 和 shebang 行,但它似乎仍然不起作用。 This is what I tired in the automator:
这就是我对自动机感到厌倦的地方:
This is what my bash_profile looks like:这就是我的 bash_profile 的样子:
And finally this is what the first lines in the Python script looks like:最后这就是 Python 脚本中的第一行的样子:
And when I then run the Automator I get the following error message:然后当我运行 Automator 时,我收到以下错误消息:
Why do I get the import error and how do I fix it?为什么我会收到导入错误,我该如何解决?
Okay, so I solve it.好的,那我解决了。 In the Automator (shell /bin/bash) I did:
在 Automator (shell /bin/bash) 中,我做了:
/Users/username/Documents/categorize_downloads.py
Before that I had change permissions on the file I wanted to run, so:在此之前,我对要运行的文件具有更改权限,因此:
chmod 755 filename
And then finally I changed the shebang to:最后我将shebang更改为:
#!/usr/local/bin/python3
It seems to be cases when "env python3" could be used instead, but in this case I had to remove "env".似乎可以使用“env python3”代替,但在这种情况下,我必须删除“env”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.