使用pxsh时无法导入pexpect的名称“spawn”

2024-04-24 13:41:29 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我要运行的代码:

from pexpect import pxssh
s = pxssh.pxssh()
if not s.login ('myip', 'myusername', 'mypassword'):
    print ("SSH session failed on login.")
    print (str(s))
else:
    print ("SSH session login successful")
    s.sendline ('ls -l')
    s.prompt()         # match the prompt
    print (s.before)     # print everything before the prompt.
    s.logout()

运行此命令时出现的错误是:

Traceback (most recent call last):
  File "test_pexpect.py", line 1, in <module>
    from pexpect import pxssh
  File "C:\Python35\lib\site-packages\pexpect\pxssh.py", line 23, in <module>
    from pexpect import ExceptionPexpect, TIMEOUT, EOF, spawn
ImportError: cannot import name 'spawn'

有人能帮我吗?我在windows上使用python3.5


Tags: theinfrompyimportsessionlinelogin