You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已安装beautifulsoup4但导入bs4提示ModuleNotFoundError求助

Fixing ModuleNotFoundError for bs4 After Installing beautifulsoup4 on Windows 10 (Python 3.6.4)

Hey there, sorry to hear you're stuck with this frustrating snag—this is a super common issue when dealing with multiple Python environments on Windows, so let's break it down step by step to get you back on track.

Step 1: Ensure pip and Python Use the Same Version

The most likely culprit is that you're installing the module with a pip tied to a different Python version than the one you're running in the shell. Here's how to check and fix it:

  1. Open Command Prompt (CMD) and confirm your active Python version:

    python --version
    

    It should display Python 3.6.4.

  2. Next, check which Python your pip is linked to:

    pip --version
    

    Look at the path in the output (e.g., ...\Python36\Scripts\pip.exe)—it should match your 3.6.4 installation.

  3. If they don't align, install the module using python -m pip (this guarantees you're using the pip tied to your current Python):

    python -m pip install beautifulsoup4
    

Step 2: Verify the Module Installed to the Correct Path

Sometimes modules end up in a directory your Python shell doesn't check. Let's confirm:

  1. In CMD, run this to find where beautifulsoup4 was installed:

    pip show beautifulsoup4
    

    Note the Location line (e.g., C:\Users\YourName\AppData\Local\Programs\Python\Python36\Lib\site-packages).

  2. Open your Python Shell and run these lines to see which directories Python scans for modules:

    import sys
    print(sys.path)
    

    Make sure the Location path from pip show is in this list. If not, you can temporarily add it for testing:

    sys.path.append("C:\\Path\\To\\Your\\site-packages")
    

    Then try import bs4 again. If it works, you might need to adjust your Python environment variables to include this path permanently, or reinstall the module.

Step 3: Force a Clean Reinstall

Corrupted installation files can also cause this issue. Let's wipe and restart:

  1. Uninstall the module first:

    pip uninstall beautifulsoup4
    

    Confirm the uninstall when prompted.

  2. Reinstall with the --force-reinstall flag to replace all files:

    python -m pip install --force-reinstall beautifulsoup4
    

Step 4: Check for Virtual Environment Conflicts (If Applicable)

If you've ever set up a virtual environment (venv) for a project, make sure you're not running your Python Shell in an inactive venv. Virtual environments have their own module sets, so if you installed beautifulsoup4 globally but are using a venv, it won't be available.

To activate your venv (if you have one), navigate to its directory in CMD and run:

Scripts\activate.bat

Then install the module again while the venv is active.

After trying these steps, open your Python Shell and run import bs4—it should work now! Don't stress, this is a super common pitfall for new Python devs, so you're not alone here.

内容的提问来源于stack exchange,提问作者Victor Hart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:52:09