我正在运行CentOS7,并在Python3.5中安装了pexpect。但是,当我调用任何方法时,它将返回一个错误,说明属性不存在。知道为什么会发生这种事吗?我读到,这可能是由于目录中的文件名pexpect.py造成的,但是在同一个目录中没有一个名为pexpect.py的文件。
$ pip3.5 freeze | grep pexpect
pexpect==4.2.1示例代码:
# This connects to the openbsd ftp site and
# downloads the recursive directory listing.
import pexpect
child = pexpect.spawn('ftp ftp.openbsd.org')
child.expect('Name .*: ')
child.sendline('anonymous')
child.expect('Password:')
child.sendline('noah@example.com')
child.expect('ftp> ')
child.sendline('lcd /tmp')
child.expect('ftp> ')
child.sendline('cd pub/OpenBSD')
child.expect('ftp> ')
child.sendline('get README')
child.expect('ftp> ')
child.sendline('bye')错误:
CentOS7虚拟机错误:
/usr/local/bin/python3.5 /media/sf_PycharmProjects/MyPyScripts/Tutorials/input_cmds
Traceback (most recent call last):
File "/media/sf_PycharmProjects/MyPyScripts/Tutorials/input_cmds", line 4, in <module>
child = pexpect.spawn('ftp ftp.openbsd.org')
AttributeError: module 'pexpect' has no attribute 'spawn'窗口错误:
Traceback (most recent call last):
File "C:/Users/home/PycharmProjects/PyCAT/Current_Version/SFTP/testsftp.py", line 4, in <module>
child = pexpect.spawn('ftp ftp.openbsd.org')
AttributeError: module 'pexpect' has no attribute 'spawn'Pexpect:
>>> import pexpect
>>> dir(pexpect)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']发布于 2018-01-17 15:22:09
好吧,对于windows错误,我可以告诉您,Pexpect.spawn在Windows上不工作。这需要对只在linux系统上提供某些模块的pypi做一些工作,spawn使用了其中的一个部分。
在Windows上,您必须使用PopenSpawn代替。
https://stackoverflow.com/questions/39728349
复制相似问题