1

I tried to use Paramiko in my Python 2.7, but I can't use it on my script.

I also install all packet

sudo pip install paramiko
pip install paramiko
sudo apt-get install python-paramiko

But It doesn't work

See my Script

 #!/usr/bin/python 
 #

 from paramiko.client import SSHClient
 import paramiko
 client = SSHClient

 client.load_system_host_keys()
 client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 client.connect("192.168.1.60")
 stdin, stdout, stderr = client.exec_command("ls -la")

 if stderr.channel.recv_exit_status() != 0:
    print stderr.channel.recv_exit_status()
    print stderr.read()

 else:
    print stdout.read()

It returns

   vitor@vitor-pc:~/Linux/Python/Arquivos de Configuração/Paramiko$ python paramiko.py
   Traceback (most recent call last):
   File "paramiko.py", line 4, in <module>
   from paramiko.client import SSHClient
   File "/home/vitor/Linux/Python/Arquivos de Configuração/Paramiko/paramiko.py", line 4, in <module>
   from paramiko.client import SSHClient
   ImportError: No module named client

I also tried to use this Answers and and delete my /usr/local/lib/python2.7 But nothing change.

This error appear only in Ubuntu? Or my code is wrong?

Community
  • 1
  • 1
Vitor Mazuco
  • 192
  • 2
  • 12

2 Answers2

1

Here is the problem

 vitor@vitor-pc:~/Linux/Python/Arquivos de Configuração/Paramiko$ python paramiko.py 

You have named your own script as paramiko.py thus python thinks your own script is the where it can find the 'paramiko' module. But it isn't. Just rename your file to something else and you will be fine.

e4c5
  • 52,766
  • 11
  • 101
  • 134
  • And one question, I remove my /usr/local/lib/python2.7, I will have any problem in future? – Vitor Mazuco May 12 '16 at 13:44
  • Glad to have helped! Don't touch /usr/local/lib/python2.7 that will be needed by countless packages that are installed on your system. In fact your system might even become unusable if you do so! If you have already deleted it please reinstall it asap – e4c5 May 12 '16 at 13:51
  • Humm, how can I reinstall? – Vitor Mazuco May 12 '16 at 13:52
  • sudo apt-get install python ought to do it. – e4c5 May 12 '16 at 13:53
1

There are two others methodes for add modules in python :

The first :

  1. Download the package.
  2. Create directory and paste the package in it.
  3. Tap in the terminal :
  4. export PYTHONPATH=$PYTHONPATH:path_of_package

The second :

  1. open python interpreter:
  2. import sys
  3. sys.path.insert(0, "path_of_package")
khelili miliana
  • 3,730
  • 2
  • 15
  • 28