簡體   English   中英

導入錯誤:沒有名為 bs4 的模塊(BeautifulSoup)

[英]ImportError: No Module Named bs4 (BeautifulSoup)

我在 Python 工作並使用 Flask。當我在我的計算機上運行我的主要 Python 文件時,它工作得很好,但是當我激活 venv 並在終端運行 Flask Python 文件時,它說我的主要文件 88275485990"No名為 bs4 的模塊。” 非常感謝任何意見或建議。

激活 virtualenv,然后安裝 BeautifulSoup4:

$ pip install BeautifulSoup4

當您使用easy_install安裝bs4時,您在系統范圍內安裝了它。 所以你的系統 python 可以導入它,但不是你的 virtualenv python。 如果您不需要在系統 python 路徑中安裝bs4 ,請將其卸載並保留在您的 virtualenv 中。

有關 virtualenvs 的更多信息,請閱讀

對於python2.x

sudo pip install BeautifulSoup4

對於python3

sudo apt-get install python3-bs4

只是標記到巴爾薩扎的答案。 跑步

pip install BeautifulSoup4

對我不起作用。 而是使用

pip install beautifulsoup4
pip3 install BeautifulSoup4

嘗試這個。 這個對我有用。 原因在這里很好解釋..

嘗試這個:

sudo python3 -m pip install bs4

我一直在互聯網上廣泛搜索。

我正在使用 Python 3.6 和 MacOS。 我已經用pip3 install bs4卸載並安裝了,但是沒有用。 似乎 python 無法檢測或搜索bs4模塊。

這是有效的: python3 -m pip install bs4

-m選項允許您添加模塊名稱。

https://docs.python.org/3/using/cmdline.html

如果您使用Pycharm ,請轉到preferences - project interpreter - install bs4

如果您嘗試安裝BeautifulSoup ,它仍然會顯示沒有名為bs4的模塊。

我會建議您使用以下命令卸載 bs4 庫:

pip卸載bs4

然后使用以下命令安裝它:

sudo apt-get install python3-bs4

當我使用以下命令安裝 bs4 庫時,我在我的 Linux Ubuntu 中遇到了同樣的問題:

點安裝bs4

如果您使用 Anaconda 進行包管理,則應執行以下操作:

conda install -c anaconda beautifulsoup4

這對我有用。

pipenv pip install BeautifulSoup4

發現答案與 BeautifulSoup 無關,真是太煩人了。 對於 linux 用戶,運行命令“python”不同,版本 2 退出,您可能忘記更改 python 的 bash 文件別名。 因此,您可能已經使用 3 創建了虛擬環境

python3 -m venv .venv

因此,要安裝東西,請使用

python3 -m pip install beautifulsoup4

不是

pip install beautifulsoup4

東西安裝在不同的版本中,你對發生的事情摸不着頭腦。

我做了@rayid-ali 所說的,除了我在 Windows 10 機器上,所以我省略了 sudo。 也就是說,我做了以下事情:

python3 -m pip install bs4

它就像一個pycharm。 無論如何,它就像一個魅力。

pip install --user BeautifulSoup4

pip3.7 install bs4

嘗試這個。 它適用於 python 3.7

許多教程/參考資料都是為 Python 2 編寫的,並告訴您使用 pip install somename。 如果您使用的是 Python 3,您希望將其更改為 pip3 install somename。

最簡單的是使用easy_install。

easy_install bs4 

如果 pip 失敗,它將起作用。

您可能想嘗試安裝 bs4

pip install --ignore-installed BeautifulSoup4

如果上述方法對您不起作用。

嘗試重新安裝模塊或嘗試使用以下命令安裝漂亮的湯

pip install --ignore-installed BeautifulSoup4

原始查詢的附錄:modules.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 命令。

如果您落后於公司代理,請嘗試使用以下命令

pip install --proxy=http://www-YOUR_PROXY_URL.com:PROXY_PORT BeautifulSoup4

更好的方法是(“-U”:將所有軟件包升級到最新的可用版本。):

$ python3 -m pip install -U pip && python3 -m pip install -U bs4 

或從 apt(Debian、Ubuntu、Mint 等)安裝:

$ sudo apt install python3-bs4

PyCharm的另一種解決方案:

轉到File -> Settings -> Python Interpreter ,單擊plus號並找到beautifulsoup4

點擊install

我也遇到了Python 3的這個問題。 就我而言,我可以通過運行來解決它:

$ pip3 install BeautifulSoup4

代替:

$ pip install BeautifulSoup4

您需要在 PATH 環境變量中包含 pip。 如果您沒有,請使用此鏈接: python -m pip install beautifulsoup4

這對我有用。 希望它也適合你。

you can try one of the following command 1- pip install BeautifulSoup4 2- pip install beautifulsoup4 3- easy_install bs4 if you are running linux you can try python -m pip install pip install BeautifulSoup4 or python -m pip install pip install bs4

來源 > https://jaridaa.com/post/3600

就我而言,什么時候做

pip install beautifullsoap4

總是安裝到我的 python3.9 package 我的位置

python3 --version

將 output 設為Python 3.10.6我通過升級 pip 並正確指向3.10而不是3.9解決了 pip3 安裝問題

然后一切都按預期工作

可能你使用pip安裝 bs4使用pip3 install bs4

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM