pythonipython

No module named html2text


I have tried various ways to install the library html2text and all end with ipython not being able in import it with the error message

"ImportError: No module named html2text"

The directory '/Users/NDunn/Library/Caches/pip/http' or its parent  directory is not
 owned by the current user and the cache has been disabled.
 Please check the permissions and owner of that directory.
 If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/NDunn/Library/Caches/pip/http' or its parent directory is not owned
by the current user and the cache has been disabled.
Please check the permissions and owner of that directory.
If executing pip with sudo, you may want sudo's -H flag.
Collecting html2text
Installing collected packages: html2text
Successfully installed html2text-2015.6.21

I have used sudo and -H sudo both of which say it has installed but then I can not import.

Any ideas on what is going on would be greatly appreciated.


Solution

  • Fixed. It turns out that IPython did not have a path to the location of where pip was placing new libraries. To test this use 'pip show html2text'(or any library you want to import to IPython), look to see it's location. Should look something like this.

    location :/usr/local/lib/python2.7/site-packages
    

    Open IPython and run 'import sys', then run 'sys.path'. If you do not see the prior location in the list then you need to append it to the list.

    Navigate to where you installed IPython and then to its profile. Path should look something like this.

    ~/.ipython/profile_default/startup/
    

    Inside create a file '00-startup.py', once done edit the file so that the first line reads 'import sys' and then below that 'sys.path.append('/usr/local/lib/python2.7/site-packages')'. This is my example so change the path appropriately.

    import sys 
    sys.path.append('/usr/local/lib/python2.7/site-packages')
    

    Save the file and now it should hopefully work.