我尝试了各种方法来安装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
和-H
sudo,这两种方法都说它已经安装,但是我无法导入。
对发生的一切有任何想法都将不胜感激。
在我的例子中(ubuntu14),它只使用了以下命令:
固定。结果发现,IPython没有指向pip放置新库的位置的路径。若要测试此项,请使用“pip show html2text”(或任何要导入到IPython的库),查看它的位置。应该看起来像这样。
打开IPython并运行“import sys”,然后运行“sys.path”。如果在列表中看不到先前的位置,则需要将其附加到列表中。
导航到您安装IPython的位置,然后导航到其配置文件。小径应该是这样的。
在创建文件“00 startup.py”内,完成后编辑该文件,使第一行读取“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
。因此,我们现在可以使用确保将
html2text
安装到解释器中,该解释器还包含PATH
中默认的ipython
可执行文件。根据路径和用户权限,您可能必须使用
sudo
获得足够的写入权限。相关问题 更多 >
编程相关推荐