【发布时间】:2014-02-09 06:58:07
【问题描述】:
所以我正在尝试创建一个setup.py 文件并在 python 中部署一个测试框架。
该库在pexpect 和easy_install 中有依赖项。所以,在安装easy_install 之后,我需要安装s3cmd,这是一个与亚马逊S3 配合使用的工具。
但是,要配置s3cmd,我使用pexpect,但是如果您想从新的VM 运行setup.py,那么我们会遇到ImportError:
import subprocess
import sys
import pexpect # pexpect is not installed ... it will be
def install_s3cmd():
subprocess.call(['sudo easy_install s3cmd'])
# now use pexpect to configure s3cdm
child = pexpect.spawn('s3cmd --configure')
child.expect ('(?i)Access Key')
# ... more code down there
def main():
subprocess.call(['sudo apt-get install python-setuptools']) # installs easy_install
subprocess.call(['sudo easy_install pexpect']) # installs pexpect
install_s3cmd()
# ... more code down here
if __name__ == "__main__":
main()
我当然知道在使用setup.py 之前,我可以创建另一个文件initial_setup.py 来安装easy_install 和pexpect,但我的问题是:在拥有它之前有没有办法import pexpect安装?库会在使用前安装,但是 Python 解释器会接受import pexpect 命令吗?
【问题讨论】: