Python Forum
ImportError: cannot import name 'beautifulsoup' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: ImportError: cannot import name 'beautifulsoup' (/thread-11568.html)



ImportError: cannot import name 'beautifulsoup' - soothsayerpg - Jul-16-2018

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.


RE: ImportError: cannot import name 'beautifulsoup' - buran - Jul-16-2018

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?


RE: ImportError: cannot import name 'beautifulsoup' - snippsat - Jul-16-2018

# 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.


RE: ImportError: cannot import name 'beautifulsoup' - soothsayerpg - Jul-18-2018

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'



RE: ImportError: cannot import name 'beautifulsoup' - buran - Jul-18-2018

It should be BeautifulSoup, not beautifulsoup


RE: ImportError: cannot import name 'beautifulsoup' - soothsayerpg - Jul-21-2018

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.


RE: ImportError: cannot import name 'beautifulsoup' - buran - Jul-21-2018

you can make virtual environment and it's even recommended, but not required