Search code examples
pythoncygwinpexpect

cannot use pexpect of python in cygwin


I was trying to use pexpect in cygwin, but failed. I try to install it like: pexpect-4.1>python ./setup.py install

But when I run the examples inside pexpect-4.1. It outputs:

Traceback (most recent call last):
  File "./examples/uptime.py", line 54, in <module>
    p = pexpect.spawnu('uptime')
AttributeError: module 'pexpect' has no attribute 'spawnu'

Solution

  • You probably use Windows version of python where sys.platform == 'win32' instead of sys.platform == 'cygwin'. There is no spawnu on Windows' pexpect:

    if sys.platform != 'win32':
        # On Unix, these are available at the top level for backwards compatibility
        from .pty_spawn import spawn, spawnu
    

    Try python packaged for Cygwin and try python -mpip install pexpect to install pexpect Python package.