skip to Main Content

I am trying to install a package in a new conda environment using the pip command. It installs, but with errors, and I get ModuleNotFoundError in the IDE.

The steps:

conda create --name facebookscraper python=3.8 all goes well

conda activate facebookscraper all goes well

conda install pip all goes well

pip install facebook-scraper
it installs, but at the end of the installation I get multiple WARNING: Target directory /opt/homebrew/lib/python3.9/site-packages/XYZPackageName already exists:

facebookscraper) macbook@macbook ~ % pip install facebook-scraper
Collecting facebook-scraper
Using cached facebook_scraper-0.2.58-py3-none-any.whl (44 kB)
Collecting demjson3<4.0.0,>=3.0.5
Using cached demjson3-3.0.5-py3-none-any.whl
Collecting dateparser<2.0.0,>=1.0.0
Using cached dateparser-1.1.1-py2.py3-none-any.whl (288 kB)
Collecting requests-html<0.11.0,>=0.10.0
WARNING: Target directory /opt/homebrew/lib/python3.9/site-packages/tzlocal already exists. Specify --upgrade to force replacement.
WARNING: Target directory /opt/homebrew/lib/python3.9/site-packages/dateutil already exists. Specify --upgrade to force replacement.
WARNING: Target directory /opt/homebrew/lib/python3.9/site-packages/requests-2.28.1.dist-info already exists. Specify --upgrade to force replacement.
WARNING: Target directory /opt/homebrew/lib/python3.9/site-packages/cssselect already exists. Specify --upgrade to force replacement.
WARNING: Target directory /opt/homebrew/lib/python3.9/site-packages/bin already exists. Specify --upgrade to force replacement.

When I run the following code on Visual Code Studio (using the facebookscraper conda environment as interpreter):

from facebook_scraper import get_posts
for post in get_posts('nintendo', pages=1):
    print(post['text'][:50])

I get the following ModuleNotFoundError:

[Running] python -u "/Users/macbook/Coding/python-facebook-scraper/main.py"
Traceback (most recent call last):
  File "/Users/macbook/Coding/python-facebook-scraper/main.py", line 1, in <module>
    from facebook_scraper import get_posts
ModuleNotFoundError: No module named 'facebook_scraper'

[Done] exited with code=1 in 0.11 seconds

I tried for force repalcement with pip install facebook-scraper --upgrade I get the same ModuleNotFoundError.

What am I doing wrong?

P.S.:
The reason why I am using pip install facebook-scraper and not conda conda install facebook-scraper is because the package facebook-scraper is not found in the conda channels.

2

Answers


  1. Chosen as BEST ANSWER

    pip was installing the packages by default to the brew directory. The solution was to tell pip to install in the site-packages directory of the virtual environment. This is what solved the problem:

    python -m pip install --target=/Users/macbook/opt/miniconda3/lib/python3.8/site-packages facebook-scraper


  2. pip is installing to /opt/homebrew/lib/python3.9 which is not te path of a conda environment, but of a python3.9 installed using brew. Maybe you have an alias defined for pip? You can check by running type pip

    Check that python calls the interpreter from your environment and then do

     python -m pip install facebook-scraper
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search