0

I'm using Server (SSH) in my local PC with PyCharm for remote development. I installed tensorflow (pip) from local PC with sudo privilege. When I run tensorflow code in terminal (MobaXterm)

python projects/example.py

Code works but can't save results data in server due to permission, but when I run same code with sudo to solve the permission error.

sudo python projects/example.py

I got the tensorflow import error.

ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/lib/python3.6/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.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

Furthermore, I set remote development environment in PyCharm and got same error using PyCharm. PyCharm always executing code from server with sudo privilege. This problem is only with tensorflow code. Other code (PyTorch, Caffe etc) working fine with sudo in terminal or in PyCharm.

Kindly suggest me some valuable solutions that

  • How to run tensorflow code with sudo privilege regarding above statement?
  • Is there any way to define some piece of code in Python which can save results data in server without sudo privilege?
  • Additional question: In remote development how we can run server code in PyCharm without sudo privilege?

I searched for solution about this problem but I'm unable to find any solution.

  • This lib(libcublas.so.9.0) from cuda library. Have you seen this issue https://github.com/tensorflow/tensorflow/issues/15604 – Mirodil Dec 25 '19 at 04:02
  • @Mirodil You didn't get my question. Without sudo tensforflow is working. So your ans is not fulfilling my question. – Muhammad Ahsan Dec 25 '19 at 04:31

1 Answers1

2

I suspect that this is because root has a different environment and environment variables than you have as a normal user.

Either perform the sudo command with the -E option to preserve your environment or set LD_LIBRARY_PATH prior to call python in your sudo command as follows:

sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64/ python projects/example.py

As this SO answer explains.

HeatfanJohn
  • 7,143
  • 2
  • 35
  • 41
  • Yeah you are right there are different environment in server. I follow the same procedure as you suggested but same problem. – Muhammad Ahsan Dec 25 '19 at 08:10
  • I solved this problem. I installed PyCharm in server using my profile and then access PyCharm GUI from MobaXterm terminal. Now tensorflow code in PyCharm from server is working but in local PC PyCharm its not working. Moreover I tested server PyCharm directly in server side using my profile because server is in my office, but tensorflow was not working... I really don't know about it that how it is possible that same code in PyCharm in server not working but when I access PyCharm in my local PC from server it's working. Anyway thanks for your answer. – Muhammad Ahsan Dec 26 '19 at 02:01