Reputation:
I am trying to use Pexpect for a python script I am writing with python 3. I tried installing the module on commmand prompt with admin privileges by using the pip install command:
pip install Pexpect
Once the module finished installing I opened IDLE and in it and tried importing the module:
import pexpect
which gave the error:
Traceback (most recent call last): File "", line 1, in import pexpect ImportError: No module named 'pexpect'
The problem is python cant see the imported module even after its installation.How can i prevent this from happening?
Upvotes: 0
Views: 3622
Reputation: 43
This might occur if you have multiple versions of Python installed on your machine. Assuming you have Python 2.7 and 3 installed, I am guessing "pip" installed pexpect under the 2.7 libraries. Easiest way around this is to add the path to your Python 2.7 packages to your sys.path.
import sys
sys.path.append('/usr/lib/python2.7/dist-packages')
The path mentioned above tends to change depending on your Python installation. So make sure to validate the path before running your script.
Alternatively, you could use pip3 to install packages for Python 3 directly. Please refer this question for instructions.
Upvotes: 1