【发布时间】:2012-07-31 19:16:10
【问题描述】:
我正在使用 Python 并使用 Flask。当我在我的计算机上运行我的主 Python 文件时,它运行良好,但是当我激活 venv 并在终端中运行 Flask Python 文件时,它说我的主 Python 文件有“没有名为 bs4 的模块”。非常感谢任何 cmets 或建议。
【问题讨论】:
标签: python beautifulsoup flask importerror
我正在使用 Python 并使用 Flask。当我在我的计算机上运行我的主 Python 文件时,它运行良好,但是当我激活 venv 并在终端中运行 Flask Python 文件时,它说我的主 Python 文件有“没有名为 bs4 的模块”。非常感谢任何 cmets 或建议。
【问题讨论】:
标签: python beautifulsoup flask importerror
PyCharm的另一种解决方案:
转到File -> Settings -> Python Interpreter,点击plus标志并找到beautifulsoup4。
点击install。
【讨论】:
更好的方法是(“-U”:将所有软件包升级到最新的可用版本。):
$ python3 -m pip install -U pip && python3 -m pip install -U bs4
或从 apt(Debian、Ubuntu、Mint 等)安装:
$ sudo apt install python3-bs4
【讨论】:
发现答案与 BeautifulSoup 无关,真是太烦人了。对于 linux 用户,运行命令“python”不同,版本 2 退出,您可能忘记更改 python 的 bash 文件别名。因此,您可能已经使用 3 with 创建了虚拟环境
python3 -m venv .venv
所以,安装东西,去吧
python3 -m pip install beautifulsoup4
不是
pip install beautifulsoup4
以不同版本安装的东西,您对发生的事情摸不着头脑。
【讨论】:
这对我有用。
pipenv pip install BeautifulSoup4
【讨论】:
我一直在互联网上广泛搜索。
我正在使用 Python 3.6 和 MacOS。我已经用pip3 install bs4 卸载并安装了,但这没有用。似乎 python 无法检测或搜索bs4 模块。
这是有效的:
python3 -m pip install bs4
-m 选项允许您添加模块名称。
【讨论】:
如果您使用公司代理,请尝试使用以下命令
pip install --proxy=http://www-YOUR_PROXY_URL.com:PROXY_PORT BeautifulSoup4
【讨论】:
原始查询的附录: 模块.py
help('modules')
$python modules.py
它列出了模块 bs4 已经安装。
_codecs_kr blinker json six
_codecs_tw brotli kaitaistruct smtpd
_collections bs4 keyword smtplib
_collections_abc builtins ldap3 sndhdr
_compat_pickle bz2 lib2to3 socket
正确的解决方案是:
pip install --upgrade bs4
应该能解决问题。
不仅如此,其他模块也会显示相同的错误。 因此,对于那些出错的模块,您必须以与上述相同的方式发出 pip 命令。
【讨论】:
我按照@rayid-ali 所说的做了,但我使用的是 Windows 10 机器,所以我省略了 sudo。也就是说,我做了以下事情:
python3 -m pip install bs4
它就像一个pycharm。无论如何,它就像一个魅力。
【讨论】:
尝试重新安装模块 要么 尝试使用以下命令安装漂亮的汤
pip install --ignore-installed BeautifulSoup4
【讨论】:
如果您使用Pycharm,请转到preferences - project interpreter - install bs4。
如果您尝试安装 BeautifulSoup,它仍然会显示没有名为 bs4 的模块。
【讨论】:
您可能想尝试使用
安装 bs4pip install --ignore-installed BeautifulSoup4
如果上述方法对您不起作用。
【讨论】:
pip3 install BeautifulSoup4
试试这个。这个对我有用。原因很好解释here..
【讨论】:
很多教程/参考都是为 Python 2 编写的,并告诉您使用 pip install somename。如果您使用的是 Python 3,您希望将其更改为 pip3 install somename。
【讨论】:
pip install --user BeautifulSoup4
【讨论】:
pip3.7 install bs4
试试这个。它适用于 python 3.7
【讨论】:
试试这个:
sudo python3 -m pip install bs4
【讨论】:
我会建议你使用这个命令卸载 bs4 库:
pip 卸载 bs4
然后使用以下命令安装它:
sudo apt-get install python3-bs4
当我使用以下命令安装 bs4 库时,我在我的 Linux Ubuntu 中遇到了同样的问题:
pip 安装 bs4
【讨论】:
如果您使用 Anaconda 进行包管理,应该执行以下操作:
conda install -c anaconda beautifulsoup4
【讨论】:
最简单的是使用easy_install。
easy_install bs4
如果 pip 失败,它会起作用。
【讨论】:
激活 virtualenv,然后安装 BeautifulSoup4:
$ pip install BeautifulSoup4
当您使用easy_install 安装bs4 时,您在系统范围内安装了它。所以你的系统 python 可以导入它,但不是你的 virtualenv python。
如果您不需要在系统 python 路径中安装bs4,请将其卸载并保留在您的 virtualenv 中。
有关 virtualenvs 的更多信息,请阅读this
【讨论】:
locale.Error: unsupported locale setting你有什么想法吗?
/usr/bin/python(在 Mac OS 上)是错误的;应该是<your path to your venv>/bin/python
只是标记到 Balthazar 的答案。跑步
pip install BeautifulSoup4
对我不起作用。而是使用
pip install beautifulsoup4
【讨论】:
对于python2.x:
sudo pip install BeautifulSoup4
对于python3:
sudo apt-get install python3-bs4
【讨论】:
crummy.com未能提供python3-bs4包名。
sudo pip install BeautifulSoup4 工作