从cron调用Tensforflow python脚本不起作用

时间:2017-10-12 11:33:31

标签: tensorflow gpu

当我从命令行调用我的Tensforflow python脚本时可以正常工作。 但当我把它称为cronjob时,我收到了这个错误:

  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory

我知道问题是什么,它与环境路径有关,更多可以在这里找到:After building TensorFlow from source, seeing libcudart.so and libcudnn errors但我不知道如何解决它所以我可以从cronjob调用python脚本。

1 个答案:

答案 0 :(得分:0)

正如in this question所述,cronjob与执行用户的环境不同。最简单的解决方案是在cronjob中手动提供一个:

source $HOME/.bashrc && python my_script.py