没有模块名为html2tex

2024-05-19 01:13:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试了各种方法来安装html2text库,结果ipython无法导入并显示错误消息

"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

我使用了sudo-Hsudo,这两种方法都说它已经安装,但是我无法导入。

对发生的一切有任何想法都将不胜感激。


Tags: piporandthe方法httplibrarysudo
3条回答

在我的例子中(ubuntu14),它只使用了以下命令:

sudo python -m pip install html2text 
html2text installed successfully.

固定。结果发现,IPython没有指向pip放置新库的位置的路径。若要测试此项,请使用“pip show html2text”(或任何要导入到IPython的库),查看它的位置。应该看起来像这样。

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

打开IPython并运行“import sys”,然后运行“sys.path”。如果在列表中看不到先前的位置,则需要将其附加到列表中。

导航到您安装IPython的位置,然后导航到其配置文件。小径应该是这样的。

~/.ipython/profile_default/startup/

在创建文件“00 startup.py”内,完成后编辑该文件,使第一行读取“import sys”,然后在该文件的“sys.path.append('/usr/local/lib/python2.7/site packages')”下。这是我的例子,所以适当地改变路径。

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

保存文件,现在应该可以工作了。

现在许多系统都带有多个版本的python,因此也可以有多个版本的IPython

当使用pip install <package>时,还不清楚包最终属于哪个解释器。

那我们怎么知道呢?由于基于unix的系统具有非常强大的外壳,我们可以使用它来解决问题:

which -a将列出ipython中的所有可执行文件。当您在shell中键入ipython时,将调用第一个。

对我来说只是: which -a ipython->;/Users/ch/miniconda/envs/sb34/bin/ipython

现在我们知道标准的ipython属于解释器/Users/ch/miniconda/envs/sb34/bin/python。因此,我们现在可以使用

/Users/ch/miniconda/envs/sb34/bin/python -m pip install html2text

确保将html2text安装到解释器中,该解释器还包含PATH中默认的ipython可执行文件。

根据路径和用户权限,您可能必须使用sudo获得足够的写入权限。

相关问题 更多 >

    热门问题