2022-08-22

ModuleNotFoundError in PIP package install in Conda Environment

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.



No comments:

Post a Comment