OSX Automator failing to run Python script with modules from shell

时间秒杀一切 提交于 2019-12-05 06:40:45

问题


I am trying to run a Python script that uses a few 3rd party modules (numpy, pandas, Twython) from Run Shell Script in OSX Automator. I wrote a hello_world.py script that runs successfully so I'm certain that the problem is due to the 3rd party modules.

In Terminal, I can successfully execute: python Desktop/my_folder/myscript.py, however when I try to run the shell script below, the shell script fails. I run Python 2.7.7 from anaconda distribution.

#!/Users/myName/anaconda/bin/python2.7

cd ~/Desktop/my_folder/
python script.py

How do I write a shell script that works for Python scripts that use 3rd party modules?


回答1:


You need to specify the absolute path to the Anaconda Python when you invoke Python, not as a shebang line (which apparently is ignored by Automator anyway). When running a shell script under Automator, your shell startup profiles are probably not being run so the changes that put the Anaconda bin directory on PATH do not happen, causing python to refer to the system Python. Try this instead.

#!/bin/sh

cd ~/Desktop/my_folder/
/Users/myName/anaconda/bin/python2.7 script.py


来源:https://stackoverflow.com/questions/24463682/osx-automator-failing-to-run-python-script-with-modules-from-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!