1

When I call my Tensforflow python script from command line works fine as expected. But when I call it as a cronjob, I get this error:

  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

I know what's the problem, it is environment path related, more can be found here: After building TensorFlow from source, seeing libcudart.so and libcudnn errors but I am not sure how to resolve it so I could call a python script from a cronjob.

Maxim
  • 52,561
  • 27
  • 155
  • 209

1 Answers1

0

As discussed in this question, cronjob doesn't have the same environment as an executing user. The simplest solution is to provide one manually right in the cronjob:

source $HOME/.bashrc && python my_script.py
Maxim
  • 52,561
  • 27
  • 155
  • 209