2017-07-16 143 views
1

我只是一個初學者使用python 2.7。請原諒我的naive-內斯沒有名爲PXSSH的模塊

我下面的代碼是不工作

import sys 
import os 
import time 
import re 
import pxssh 

a = ['192.168.50.11', '192.168.50.12'] 

for i in a: 
    Host = i 
    print Host 
    User = "xyz" 
    Password = "abc" 
    tn = pxssh.pxssh(Host) 
    tn.read_until("login as: ") 
    tn.write(User + "\n") 
    tn.read_until("Password: ") 
    tn.write(Password + "\n") 
    tn.read_until("#") 
    tn.write("show run\n") 
    time.sleep(3) 
    output = tn.read_all() 
    time.sleep(3) 
    f = open("C:/Python27/file/"+ Host + ".txt", "w+") 
    f.write(output) 
    f.close() 
    tn.close() 

它給了我以下錯誤:

Traceback (most recent call last): 
    File "C:/Python27/backup_config_files", line 5, in <module> 
    import pxssh 
ImportError: No module named pxssh 

請讓我知道我可以解決與蟒蛇此pxssh模塊問題2.7 in windows

回答

0

使用安裝鏡頭

pip install pexpect 

然後導入使用

from pexpect import pxssh 

參考文獻:docs

0

這個問題類似於this one

pxssh是一類,您必須從導入模塊pexpect

你進口會是什麼樣子:

from some.location.pexpect import pxssh 

如果沒有pexpect模塊,在bash pip install pexpect在您的工作環境。