重要错误:没有名为pexp的模块

2024-04-20 09:21:44 发布

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

我正在使用Fabric,希望使用fexpect。我有以下Python脚本:

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')

执行时,出现以下错误:

[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

我使用的是virtualenv,实际安装的是pexpect:

(venv)PALM00545424A:woopup i841712$ pip install pexpect
Requirement already satisfied (use --upgrade to upgrade): pexpect in ./venv/lib/python2.7/site-packages

Tags: installtorunpostgresqlwithitoutxxx
3条回答

找到了解决办法。

pexpect不是远程机器Python安装的一部分。

我只是执行了

sudo -E pip install pexpect 

在远程机器上。

实际上,如果脚本使用fexcept,则需要运行的命令实际上是:

sudo -E pip install fexpect 

不是对您的问题的直接回答,但是像chef、puppet或salt这样的工具更适合安装系统包。

相关问题 更多 >