Conda环境下使用PIP安装facebook-scraper包遭遇ModuleNotFoundError问题求助
Let's break down what's going wrong here and fix it step by step:
The Root Cause
Look closely at the warnings from your pip install command—they're pointing to /opt/homebrew/lib/python3.9/site-packages, which is your system Python 3.9's package directory, not the Python 3.8 Conda environment you created.
This means when you ran pip install, you weren't using the pip that belongs to your facebookscraper Conda environment. Instead, you were invoking your system-wide pip, so the package got installed outside your target environment. That's why your IDE (which is using the Conda environment's Python) can't find facebook_scraper.
How to Fix It
Here are the most reliable ways to get the package installed in the right place:
Use
python -m pipinstead of plainpip
Activate your Conda environment first, then run:python -m pip install facebook-scraperThis forces the command to use the
pipassociated with the currently active environment's Python interpreter—no chance of accidentally using the systempip.Verify your
pippath first
Before installing, confirm you're using the correctpipby running:which pipThe output should point to your Conda environment's
bindirectory, like~/miniconda3/envs/facebookscraper/bin/pip(or the path where your Conda is installed). If it shows/opt/homebrew/bin/pip(systempip), try reactivating your environment or restarting your terminal—sometimes Conda's PATH changes don't take effect immediately.Reinstall pip in your Conda environment (if needed)
If the environment'spipis still misbehaving, force a reinstall of pip within the environment:conda activate facebookscraper conda install pip --force-reinstallThis ensures the environment has its own properly linked
pip.
Verify the Installation
After installing, confirm the package is in your environment by running:
pip list | grep facebook-scraper
Or test it directly with Python:
python -c "import facebook_scraper; print('Success! Version:', facebook_scraper.__version__)"
If this runs without errors, your IDE should now be able to import the module correctly.
内容的提问来源于stack exchange,提问作者SimbaNinja

