没有名为 html2text 的模块
No module named html2text
我尝试了各种方法来安装 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 两者都说它已经安装但是我无法导入。
任何关于正在发生的事情的想法都将不胜感激。
如果您安装的 Python
版本很少,请使用 sudo pip install --target=path/to/your/pythonXX/site-packages html2text
然后软件包将可用于某些 Python 解释器。然后在你的代码中使用 import html2text
editor/Python shell
现在很多系统都带有多个版本的python,因此也可以有多个版本的IPython
。
当使用 pip install <package>
时,并不能立即清楚包最终属于哪个解释器。
那我们怎么知道呢?由于基于unix的系统自带一个非常强大的shell我们可以用它来解决问题:
which -a
将列出您 PATH
中的所有 ipython
可执行文件。当您在 shell.
中键入 ipython
时将调用第一个
对我来说只是:
which -a ipython
-> /Users/ch/miniconda/envs/sb34/bin/ipython
现在我们知道标准ipython
属于解释器/Users/ch/miniconda/envs/sb34/bin/python
。所以我们现在可以使用
而不是调用 pip install html2text
/Users/ch/miniconda/envs/sb34/bin/python -m pip install html2text
确保 html2text
安装到解释器中,该解释器还包含 PATH
中的默认 ipython
可执行文件。
根据路径和您的用户权限,您可能必须使用 sudo
才能获得足够的写入权限。
已修复。事实证明 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/站点包')'。这是我的示例,因此请适当更改路径。
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
保存文件,现在它应该可以工作了。
在我的例子中(ubuntu14)它只用了下面的命令:
sudo python -m pip install html2text
html2text installed successfully.
我尝试了各种方法来安装 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 两者都说它已经安装但是我无法导入。
任何关于正在发生的事情的想法都将不胜感激。
如果您安装的 Python
版本很少,请使用 sudo pip install --target=path/to/your/pythonXX/site-packages html2text
然后软件包将可用于某些 Python 解释器。然后在你的代码中使用 import html2text
editor/Python shell
现在很多系统都带有多个版本的python,因此也可以有多个版本的IPython
。
当使用 pip install <package>
时,并不能立即清楚包最终属于哪个解释器。
那我们怎么知道呢?由于基于unix的系统自带一个非常强大的shell我们可以用它来解决问题:
which -a
将列出您 PATH
中的所有 ipython
可执行文件。当您在 shell.
ipython
时将调用第一个
对我来说只是:
which -a ipython
-> /Users/ch/miniconda/envs/sb34/bin/ipython
现在我们知道标准ipython
属于解释器/Users/ch/miniconda/envs/sb34/bin/python
。所以我们现在可以使用
pip install html2text
/Users/ch/miniconda/envs/sb34/bin/python -m pip install html2text
确保 html2text
安装到解释器中,该解释器还包含 PATH
中的默认 ipython
可执行文件。
根据路径和您的用户权限,您可能必须使用 sudo
才能获得足够的写入权限。
已修复。事实证明 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/站点包')'。这是我的示例,因此请适当更改路径。
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
保存文件,现在它应该可以工作了。
在我的例子中(ubuntu14)它只用了下面的命令:
sudo python -m pip install html2text
html2text installed successfully.