Sunday, January 23, 2011

how to get python pexpect module on windows?

From quite a long time i was looking for a python module like "pexpect" for windows OS. I have wasted so many hours of mine to get some work around, finally what i got might help you all.

1. We can install pexpect module of python on windows . :) :)  But it requires cygwin installation.

2. Download Cygwin and install from any official site. Eg:

3. Once cygwin installation has completed, start cygwin session. (execute: cygwin.bat from installation directory or double click shortcut  of cygwin on your desktop.)

4. All windows directories will be referenced with respect to /cygdrive . Eg: D: directory will be referenced as /cygdrive/d/

5. execute following given below commands: Make sure python is installed on your system if not please install before executing given below commands.

#### assuming your python installation directory is C:/python25 ####
$ alias pythonpath=/cygdrive/c/python25/python
$ export pythonpath

6. Now check all well or not :

$ which python

#### if every thing will be ok It will return "/usr/local/python"  other wise go through steps given above and check u did all as mentioned there #############

7. Now get your pexpect.tar.gz file.

$ tar -xvzf pexpect.tar.gz
$ cd pexpect

$ python build
$ python install

8. Now you can use pexpect in your python script:

Note: you can use pexpect module on python from cygwin prompt only (For: Windows OS).

For Any Other Assistance Please write me on :


PRATEEK said...

Its working fine ...

pawan kumar singh said...

you can use it without cygwin session(or prompt) and it works.
Let your cygwin install directory is :

so you can use python from cygwin module as:


replace pythonxx with your python version like:
python25,python26 or python31

subbulakshmi vinayagam said...

I tried ur commands. But i got stuck after the following command:
Subbulakshmi@DHC008 /cygdrive/c/cygwin/usr/local/bin/pexpect-2.3
$ python build
/usr/local/bin/python.exe: error while loading shared libraries: python27.dll: cannot open shared object file: No such file or directory

please guide me...

Thanks in advance

pawan singh said...

Which python version are you using ? and your python bin directory has that dll or not ?