How to install and import python module in the same script?
我想写一个安装程序脚本,安装pexpect然后使用它。类似的东西
1 2 3 4 | ... os.system('easy_install pexpect') import pexpect ... |
问题是导入失败,消息
1 2 | import pexpect ImportError: No module named pexpect |
我怎样才能达到一个同等的结果呢?
它不能与安装工具一起工作,因为安装工具将把
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | >>> import pexpect Traceback (most recent call last): File"<stdin>", line 1, in <module> ImportError: No module named pexpect >>> import os >>> os.system('bin/pip install pexpect') Downloading/unpacking pexpect Downloading pexpect-2.4.tar.gz (113kB): 113kB downloaded Running setup.py egg_info for package pexpect Installing collected packages: pexpect Running setup.py install for pexpect Successfully installed pexpect Cleaning up... 0 >>> import pexpect >>> |