2014-03-26 31 views
5

我正在使用Fabric並希望使用fexpect。我有以下Python腳本:ImportError:沒有名爲pexpect的模塊

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 
+0

是吧'fexpect'或'pexpect'? – Selcuk

+1

fexpect是一個依賴Python的特性的Fabric擴展。實際上這是正確的。 – mitchkman

回答

13

找到了解決辦法。

pexpect不是遠程計算機Python安裝的一部分。

我簡單地在遠程計算機上執行

sudo -E pip install pexpect 

+0

很高興你找到了解決方案,但不應該有必要在遠程安裝pexpect。該模塊通常與fexpect命令腳本一起發送。 –

+0

如果您想進一步隨時在https://github.com/ilogue/fexpect/issues?state=open上發佈此問題,可以查看「ls/tmp」的輸出遙遠的 –

0

不是你的問題的直接答案,但像廚師,木偶或鹽的工具更適合安裝系統軟件包。

+0

是的,我已經考慮過了,但Fabric比例子輕得多廚師更直接 – mitchkman

1

在如果你的腳本使用fexcept事實上,你需要運行命令實際上是:

sudo -E pip install fexpect 
相關問題