The code is just
from bs4 import BeautifulSoup
print(BeautifulSoup.__file__)
and the error shows
File "/path/to/wtfisgoingon.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup' from 'bs4' (unknown location)
Downloaded BeautifulSoup4 on Linux Ubuntu 20.04 using:
sudo pip3 install bs4
and sudo pip3 install beautifulsoup4
, and sudo pip3 list
will see bs4 and beautifulsoup downloaded (version 0.0.1 and 4.11.1 respectively).
Checked everywhere and most people import it with "beautifulsoup" or "Beautifulsoup4" but I think my import is in correct format. Or people name the file bs4.py or some name included in the module or something so it won't work, however my file name is something impossible to be seen in the module.
Please help! Thank you.
CodePudding user response:
You should only need to import beautifulsoup4. I find it useful to use a venv or virtualenv, and once you are in the virtual environment all you need to import is python3 -m pip install {package}
. You can create a virtual environment using python3 -m venv {venv name}
, and activate using cd {venv name}
and then source bin/activate
(this is for mac, pretty sure it works on other os) https://docs.python.org/3/tutorial/venv.html this might help
CodePudding user response:
you need create venv
python -m venv myvenv
then use venv pip3 install bs4
from bs4 import BeautifulSoup