Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named pexpect

I am using Fabric and would like to use fexpect. I have the following Python script:

from ilogue.fexpect import expect, expecting, run

(...)

def install_postgresql(profile):
print("!!! Installing PostgreSQL...")
print(' -> Doing pre-cleanup...')

# Remove PostgreSQL if it exists

prompts = []
prompts += expect('Do you want to continue [Y/n]? ', 'Y')

with settings(warn_only=True):
    with expecting(prompts):
        run('sudo apt-get purge postgresql')

print(' -> Doing actual installation...')

# Install PostgreSQL

prompts = []
prompts += expect('Do you want to continue [Y/n]? ', 'Y')

with expecting(prompts):
    run('sudo apt-get install postgresql')

# In some cases PostgreSQL has issues with Ubuntu's default kernel params
# that prevent PostgreSQL to start automatically, so we try to start it
# TODO: Fix it
with settings(warn_only=True):
    run('sudo service postgresql start')

When executing I get the following error:

[xxx.xxx.xxx.xxx] out: Traceback (most recent call last):
[xxx.xxx.xxx.xxx] out:   File "/tmp/fexpect_MbW3QP6Zpy5KBjBGQcaYxi", line 4, in <module>
[xxx.xxx.xxx.xxx] out:     import pexpect
[xxx.xxx.xxx.xxx] out: ImportError: No module named pexpect

I am using virtualenv and pexpect is actually installed:

(venv)PALM00545424A:woopup i841712$ pip install pexpect
Requirement already satisfied (use --upgrade to upgrade): pexpect in ./venv/lib/python2.7/site-packages
like image 423
mitchkman Avatar asked Mar 26 '14 18:03

mitchkman


People also ask

What is Pexpect in Python?

Pexpect is a Python module for spawning child applications and controlling them automatically. Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup scripts for duplicating software package installations on different servers.


2 Answers

In fact if your script uses fexcept, the command you need to run is actually:

sudo -E pip install fexpect 
like image 170
Alexandre Mazel Avatar answered Oct 27 '22 07:10

Alexandre Mazel


Found the solution.

pexpect was not part of the remote machine's Python installation.

I simply executed

sudo -E pip install pexpect 

on the remote machine.

like image 35
mitchkman Avatar answered Oct 27 '22 08:10

mitchkman