Reputation: 4029
I want to write an installer script which installs pexpect and then uses it. Something like
...
os.system('easy_install pexpect')
import pexpect
...
The problem is that import fails, with the message
import pexpect
ImportError: No module named pexpect
How can I accomplish an equivalent result?
Upvotes: 1
Views: 7905
Reputation: 172249
It will not work with setuptools, because setuptools will install pexpect
as an egg, and then add it to easy-install.pth
, which is checked only on startup. You can get around this in various ways, but it's easier to instead use pip
to install pexpect:
>>> 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
>>>
pip
will install modules in a less magical (but perhaps messier) way, and the modules end up on sys.path directly, so that works.
Upvotes: 1