-1

Every time when i try to import the bs4 module i get this error

ModuleNotFoundError: No module named 'bs4'

When i try to install the bs4 module i get this message on the console:

C:\Users\gabri>pip install bs4
Requirement already satisfied: bs4 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (0.0.1)
Requirement already satisfied: beautifulsoup4 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (from bs4) (4.9.3)
Requirement already satisfied: soupsieve>1.2 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (from beautifulsoup4->bs4) (2.2.1)

When i try to import the requests module that's working i get this message:

C:\Users\gabri>pip install bs4
Requirement already satisfied: bs4 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (0.0.1)
Requirement already satisfied: beautifulsoup4 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (from bs4) (4.9.3)
Requirement already satisfied: soupsieve>1.2 in c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages (from beautifulsoup4->bs4) (2.2.1)

My python version is:

Python 3.9.5

My pip version is:

pip 21.1.2 from c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)

I used to have anaconda installed and then i installed python again. I read in some post that maybe the problem was happening because of two versions of python installed than i uninstall anaconda and jupyter. However nothing change. Some people said to me that my pip was install in another python besides the one i am trying to run, but i dont know how to change that. The code i'm trying to run in this

import requests as r
from bs4 import BeautifulSoup

try:
    result = r.get('https://www.google.com.br/search?q=Python')
    
except Exception as err:
    print("Something went wrong: ",err)
    
else:
    response = result.text
    soup = BeautifulSoup(response,'html.parser')
    
    print(soup.title)
    print(soup.title.string)

And the error is this:

>>> %Run teste.py
Traceback (most recent call last):
  File "C:\Users\gabri\teste.py", line 2, in <module>
    from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'

I think that my pip is install in this path:

pip 21.1.2 from c:\users\gabri\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)

and my python is install in this path:

C:\Users\gabri\AppData\Local\Programs\Python\Python39\python39.zip
C:\Users\gabri\AppData\Local\Programs\Python\Python39\DLLs
C:\Users\gabri\AppData\Local\Programs\Python\Python39\lib
C:\Users\gabri\AppData\Local\Programs\Python\Python39
C:\Users\gabri\AppData\Local\Programs\Python\Python39\lib\site-packages

Thats a picture of my paths on windows

enter image description here

I try put the file with the code that i'm trying to run inside the path of bs4 and it worked. But i would like to know if there is an easy method besides that

  • Welcome to StackOverflow! You added the output of `pip install bs4` twice, I guess one of them was supposed to be different content? How do you run your script? If you run `python teste.py` (assuming your script is named "teste.py") from the console, where you also ran `pip install bs4`, does it work? If so, [this](https://stackoverflow.com/questions/56658553/module-not-found-error-in-vs-code-despite-the-fact-that-i-installed-it) might answer your question. – He3lixxx May 29 '21 at 17:10
  • Hi @He3lixxx, i posted twice by mistake. So the problem was that my actual IDE (Thonny) was importing the modules from a messed up path and was not the path that i installed the modules with pip. So to correct i change the importation path in the IDE settings. – Gabriel Padilha May 31 '21 at 09:35

1 Answers1

0

So with the helping of @He3lixx i found the answer to the question. My IDE, Thonny was using the wrong sys path to import the bs4 module. The module that pip install bs4 was in the python installation folders. So i change the paths imports in the IDE settings. To figure out what paths the IDE was using and compare to the path the bs4 was installed i use this code in the IDE shell:

import sys 

for sys in sys.path:
    print (sys)