Python Forum
ImportError: cannot import name 'beautifulsoup'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImportError: cannot import name 'beautifulsoup'
#1
Hi guys! Just new here.

I'm using Windows-7, the latest Python 3.7 and the latest Beautifulsoup4.6 but still getting those error. Tried a variety of mixing things up, searching the web, youtube tutorials but still getting that error.

I mean it's working fine when I try to run to check for no errors using Python IDLE. But as we know, that's already inside Python. I usually use Sublime and Windows Powershell to run things.

Hope I had put all the information and thanks in advance for the help.

Oh, and btw, still getting the same error using Mac.
Reply
#2
post your code in python tags. Post the full traceback you get - in error tags. how did you install BeautifulSoup? Do you have more than one python installation?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
# Test that python use 3.7
C:\>python -c "import sys; print(sys.executable)"
C:\python37\python.exe

# Test that pip use 3.7
C:\>pip -V
pip 10.0.1 from c:\python37\lib\site-packages\pip (python 3.7)

# Install
C:\>pip install -U beautifulsoup4
Requirement already up-to-date: beautifulsoup4 in c:\python37\lib\site-packages (4.6.0)

# Test that it work
C:\>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
>>> bs4.__version__
'4.6.0'

>>> # Normal import 
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup('html', 'html.parser') # Or 'lxml' for faster parser
Python 3.6/3.7 and pip installation under Windows
Follow this then should all be working,if use Editors eg VS Code, PyCharm ...ect.
So most there config choice of which interpreter point to 3.7.
Reply
#4
Apology for the late response. The forum notification ends up on my spam email folder.
Used Windows Powershell to install beautifulsoup.
python -m pip install bs4
The code is just a practice code from a video lesson and just had a simple html code inside the same .py sheet. Nothing fancy, just trying to output the same html by calling
soup = beautifulsoup(html, "html.parser") 
print(soup) 
print(type(soup))
Here's the error.
Error:
Traceback (most recent call last): File "beautifulscrape.py" line 1, in <module> from bs4 import beautifulsoup ImportError: cannot import name 'beautifulsoup'
Reply
#5
It should be BeautifulSoup, not beautifulsoup
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
Do I need an venv for this to work? Coz to my surprise scrapy needs a new folder to create it's venv in order for it to run. Just also asking if I might be missing that part? Thanks for the answer buran, will try that later.
Reply
#7
you can make virtual environment and it's even recommended, but not required
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020