Paramiko SSH connection does not have access to GPU with tensorflow


Using Python’s paramiko I try to access a server I own remotely via an SSH connection. This server has a python script that I execute via my SSH connection (I actually execute a .sh file that calls this python script). The first line of this python script is:

print("Devices:", tf.config.experimental.list_physical_devices())

Here I only see:

Devices: [PhysicalDevice(name=’/physical_device:CPU:0′, device_type=’CPU’)]

If I execute the same .sh file after opening the SSH connection with PuTTY that same line of code generates the following result:

Devices: [PhysicalDevice(name=’/physical_device:CPU:0′, device_type=’CPU’), PhysicalDevice(name=’/physical_device:GPU:0′, device_type=’GPU’)]

Here it does show the GPU as available. I suppose this is related to the way I open the paramiko SSH connection. This is the code:

ssh = paramiko.SSHClient()  

ssh.connect(ip, port=port, username=u, password=pass)

cmd_to_execute = "./" + shFileName + ".sh"

ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd_to_execute)
for line in ssh_stdout:
for line in ssh_stderr:
    print('ERR: ' + line.strip('\n'))

Why do I not have access to the GPU when the SSH connection is established using paramiko?


If I allow tensorflow logs to be displayed, I get this error:
W tensorflow/stream_executor/platform/default/] Could not load dynamic library ‘’; dlerror: cannot open shared object file: No such file or directory

And others that look more or less like this one but changing the .11.0

On the other hand, if I use PuTTY it loads the libraries correctly:
I tensorflow/stream_executor/platform/default/] Successfully opened dynamic library


Following the comments made by Martin Prikryl and DR. Snoopy I was able to solve the issue by modifying the startup scripts to set the same PATH for all sessions. I did this by modifying two files.

$HOME/.profile file original code had this part

if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"

and I changed it to:

# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"

$HOME/.bashrc original code had this part:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;

and I changed it to:

# If not running interactively, don't do anything
#case $- in
#    *i*) ;;
#      *) return;;

This way now the same libraries are loaded without taking into account which way I established the connection.

Answered By – Bobbick

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published