I am working with python 2.7 on Windows 10 and I am using the Spyder IDE. I'm trying to extract a table from the following link:
http://www.espn.com/nhl/statistics/player/_/stat/points/sort/points/year/2015/seasontype/2
using pandas. My code reads:
import pandas as pd
import html5lib
url = 'http://www.espn.com/nhl/statistics/player/_/stat/points/sort/points/year/2015/seasontype/2'
table = pd.read_html(url)
but I get the error message that the html5lib module is not installed. I have installed it using pip, but even after restarting Spyder, I still get the message
ImportError: No module named html5lib
I have looked everywhere and no solution seems to work for me: unistalling and installing html5lib, updating pip, updating anaconda3, etc. Can anyone help me?
EDIT
Through the Command Window in Spyder I used
easy_install html5lib
and now, running pip list, html5lib (1.0b10) appears, but I still get the same message: ImportError: No module named html5lib.
Related
I've installed beautifulsoup4 using pip and pip3. When I run my Python shell, I get:
import bs4
print(bs4)
<module 'bs4' from '/Users/myUserName/Desktop/Dev/virtual_env/lib/python3.10/site-packages/bs4/init.py'>
But when I try the same thing in IDE (Sublime), I get:
ModuleNotFoundError: No module named 'bs4'
I'm stumped, I downloaded pandas right after and it worked just fine in my IDE. Any tips to fix this problem? Or do I just try another web scraping tool?
This shows that you are in a different interpreter. What you can do is to append the path of beautifulsoup4 into your working environment before importing.
import sys
sys.path.append("/Users/jimmyfl0/Desktop/Dev/mine/the_venv/lib/python3.10/site-packages")
import bs4
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
Python version: 3.9.5
pip version: 21.1.1
BeautifulSoup4 version: 4.9.3
from bs4 import BeautifulSoup
with open('home.html', 'r') as html_file:
content = html_file.read()
print(content)
I have been trying to use the BeautifulSoup4 library but it just won't work. In vscode, it shows the indication that bs4 is there when I do CTRL+click on bs4 written in Code. But it still gives ModuleNotFoundError: No module named 'bs4'
I have installed it properly with pip3 as shown in the below screenshot
The version of python I am using in VS Code is shown in below Image
Just a side note. I also used some other packages such as Camelcase and that one worked fine. Idk why this one is not working properly. I couldn't find any proper related solution for it in the existing solutions for it.
I had python3 installed 2 times.. 1 from the Windows store and the other from python exe file. python3 command referred to windows installed python3 and python referred to exe file installed python3. BeautifulSOup installed via pip3 was linked to the python command instead of python3 so that was the reason it wasn't working.
after checking for paths of python and python3 everything got clarified and the problem solved thanks to the hint given by #Y.R in the comments section of the main post.
On MacOS, I installed homebrew, then installed pip.
Trying to use a Python scraper that uses "BeautifulSoup" package.
Ran: pip install -r requirements.txt
requirements.txt includes:
BeautifulSoup
ipython
BeautifulSoup gives an error, after googling I realized that there is a new version. so I ran:
pip install beautifulsoup4
seems to have installed correctly. Then I ran the scraping script and I got the following error:
Traceback (most recent call last):
File "scrape.py", line 3, in <module>
from BeautifulSoup import BeautifulSoup
ImportError: No module named BeautifulSoup
I tried changing BeautifulSoup to BeautifulSoup4 in the script, but it is the same error.
Anything else I can try?
This is the script I am trying to use: https://github.com/jojurajan/wp-content-scraper
This is essentially because beautifulsoup4 has a different interface to
its previous versions.
The old version exposes a module named BeautifulSoup.
from BeautifulSoup import BeautifulSoup
The new way to import the module in Python would be.
from bs4 import BeautifulSoup
However, it seems that you are using a scraper written by someone else relying on the old BeautifulSoup. To solve this you have to install the old version.
Maybe you can share the complete requirements.txt and we will see what is the version it's using.
The code in question was created by me. The scraper uses Python 2.7 and older version of BeautifulSoup. It was a mistake on my part to not mention the Python version and BeautifulSoup version in requirements.txt. Newbie mistakes while releasing code into the wild. :)
I have updated the README to specify about the supported Python version.
Every single dependency I try to install results in a ton of troubleshooting before I can get IDLE to recognise that it's installed.
I'm on a Mac, and I'm using the Terminal's pip install. I also have two versions of IDLE – one for Python 2, the other for 3.
pip install says "beautifulsoup" is installed
pip3 install says "beautifulsoup" is installed, and yet it doesn't appear that IDLE knows that it is.
I've tried "import beautifulsoup4, import beautifulsoup, from bs4 import beautifulsoup..."
Why is this happening for every dependency I install?
It's not beautifulsoup or Beautifulsoup
Try this from bs4 import BeautifulSoup