简体   繁体   English

在 shell /bin/bash 中运行 Python 3 脚本时 Automator 出现 importError

[英]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 的样子: bash_profile

And finally this is what the first lines in the Python script looks like:最后这就是 Python 脚本中的第一行的样子: Python 3 脚本

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.

相关问题 python 脚本 ImportError:在 Automator 中运行 shell 脚本时没有名为“webbot”的模块 - python script ImportError: No module named 'webbot' when running shell script in Automator ImportError:无法导入名称_remove_dead_weakref-运行python script.py时没有错误,从bash shell脚本中运行script.py时错误 - ImportError: cannot import name _remove_dead_weakref - no error when running python script.py, error when running script.py from bash shell script 使用 macOS Automator 从 conda env 中运行 Python 代码的 Shell 脚本 - Shell script running Python code from within conda env using macOS Automator python ImportError Openvino by script 和 shell - python ImportError Openvino by script and by shell 当bash脚本运行时,python弹出窗口 - python popup window while bash script running 在bash脚本中运行时刮擦“ ImportError” - Scrapy “ImportError” when running inside bash script 运行python脚本时出现ImportError - ImportError when running python script 在bash / python / perl脚本中运行一系列交互式shell命令 - running series of interactive shell commands in bash/python/perl script 在python中运行bash脚本并等待shell命令完成 - Running bash script within python and wait for shell command to complete Bash 在 shell 脚本中内联运行 python 仍然无法正常工作 - Bash running python inline in shell script still not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM