I have switched from Pycharm to using Sublime Text, and importing/installing beautifulsoup4 and requests, (I will probably have the same problem with other modules) seems rather complicated.
I've tried installing them both by typing the followling in my terminal
sudo pip install requests
and the same for beautifulsoup4 (I have pip installed).
When I, in terminal, type
python
and then
import requests
and
from bs4 import beautifulsoup4
It says for requests:
ImportError: No module named requests
and for soup:
ImportError: cannot import name beautifulsoup4
What am I doing wrong? I haven't even tried doing anything in Sublime Text yet.
cannot import name beautifulsoup4
means that you are trying to this:
from bs4 import beautifulsoup4
instead of:
from bs4 import BeautifulSoup
Related
If we go to: https://pypi.org/project/bs4/ we can read:
This is a dummy package managed by the developer of Beautiful Soup to prevent name squatting. The official name of PyPI’s Beautiful Soup Python package is beautifulsoup4. This package ensures that if you type pip install bs4 by mistake you will end up with Beautiful Soup.
So given the following line in python: from bs4 import BeautifulSoup, Comment How can I replace it with beautifulsoup4? ie I don't want to install bs4 package at all as it's just a dummy package as claimed...
A distribution package and the import package it contains do not necessarily have the same name. In other words the thing that you install does not necessarily have the same name as the thing you import. Even though the convention is to give them the same name, there are exceptions. And "Beautiful Soup" is such an exception.
So you pip install beautifulsoup4 but you import bs4.
With that said, you can probably safely uninstall bs4:
python -m pip uninstall bs4
as long as you still have beautifulsoup4 installed:
python -m pip install beautifulsoup4
python -m pip show beautifulsoup4
I installed beautifulsoup4 on my mac but when I tried to import the module in spyder, it says ModuleNotFoundError: No module named 'beautifulsoup'
I have tried importing it with:
import beautifulsoup4
import beautifulsoup
from bs4 import beautifulsoup
import bs4
etc...
I have also tried reinstalling the module in terminal and it says that it is already installed.
I have also checked that it was installed in python 3.9 which is the same version Spyder says it is using on my computer.
I am so confused please help! Where is this module
Update: I think I need a separate environment so I tried to download miniconda but when I try to install it it says that it can't install because I already have it but when I run any conda command in terminal it says command not found so I don't know how to get miniconda
You should check your code. The tutorials I see (there are many online) all import beautifulsoup this way (casing matters - the B and the S are upper case!):
from bs4 import BeautifulSoup
Example:
https://beautiful-soup-4.readthedocs.io/en/latest/#making-the-soup
I got error when ran a flask app. This project includes scraping so I installed BeatifulSoup4 in python virtual env. When I ran flask, I got error.
ModuleNotFoundError: No module named 'bs4'
But I installed BeautifulSoup4 correctly. pip3 install beautifulsoup4
There is a weird thing.
When I wrote at terminal, it imported bs4 successfully.
You have to install bs4 package for running beautifulsoup4. If you install only beautifulsoup4, then it won't work as you are using the following import:
from bs4 import BeautifulSoup
Also, it won't work because BeautifulSoup is the sub-package of bs4.
I downloaded Python 3.7 and am running a script with "from bs4 import BeautifulSoup" and am receiving the following error on execution;
"File "myscript.py", line 3, in
from bs4 import BeautifulSoup ImportError: No module named bs4"
When I type "pip3 install bs4" or "pip3 install BeautifulSoup4" in the terminal I get the following;
"Requirement already satisfied: bs4 in
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
(0.0.1) Requirement already satisfied: beautifulsoup4 in
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
(from bs4) (4.6.3)"
Executing "import bs4" and "from bs4 import BeautifulSoup" in IDLE don't error out.
Any idea about what's going on?
Just pip install bs4.
Probably, you are maintaining different versions of Python.
check if you have more than one version of python, if so add the path of python 3.7 in the system setting and try removing the older python if possible
and then pip install BeautifulSoup
I had a similar problem with importing bs4. There is a similar question with many answers. I tried many things and nothing worked but when I installed poetry [https://python-poetry.org/ ]
$ poetry add pendulum
It sorted dependencies for me so I was able to import bs4.
I am trying to import beautiful soup in my script, but get a module not found error.
Error Message
But the problem is that when i try to install it, i get the message below:
Ajays-MacBook-Pro:/ aj$ pip install bs4
Requirement already satisfied: bs4 in /anaconda/lib/python2.7/site-packages
Requirement already satisfied: beautifulsoup4 in /anaconda/lib/python2.7/site-packages (from bs4)
What am I doing wrong here?
Note: I tried importing bs4 in Jupyter notebook and it works without any issues.
You use different version of Python in the PyCharm, you should add the Python in the /anaconda folder in the PyCharm settings.
You just need to install BeautifulSoup4 from the terminal in pycharm.
Then when you try to import it in your code you need to change this statement
from BeautifulSoup import BeautifulSoup
to this
from bs4 import BeautifulSoup
That error will be solved.