Ubuntu 14.04: ImportError: No module named client

百般思念 提交于 2019-12-13 01:56:09

问题


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?


回答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.




回答2:


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")


来源:https://stackoverflow.com/questions/37188389/ubuntu-14-04-importerror-no-module-named-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!