简体   繁体   中英

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:

"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. 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 3 脚本

And when I then run the Automator I get the following error message:

错误信息

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:

/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:

#!/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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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