cannot import name 'BeautifulSoup' from 'bs4' - python-3.x

I am using Python 3.7.0
I am not able to use BeautifulSoup attribute of bs4
I have reinstalled the library but is still not working.
from bs4 import BeautifulSoup
import csv
html = open("table.html").read()
soup = BeautifulSoup(html)
table = soup.find("table")
output_rows = []
for table_row in table.findAll('tr'):
columns = table_row.findAll('td')
output_row = []
for column in columns:
output_row.append(column.text)
output_rows.append(output_row)
with open('output.csv', 'wb') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(output_rows)
it is throwing following error:
Traceback (most recent call last):
File "D:\Automation\ReadHtml\html.py", line 1, in <module>
from bs4 import BeautifulSoup
File "D:\Python37\lib\site-packages\bs4\__init__.py", line 34, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "D:\Python37\lib\site-packages\bs4\builder\__init__.py", line 7, in <module>
from bs4.element import (
File "D:\Python37\lib\site-packages\bs4\element.py", line 19, in <module>
from bs4.formatter import (
File "D:\Python37\lib\site-packages\bs4\formatter.py", line 1, in <module>
from bs4.dammit import EntitySubstitution
File "D:\Python37\lib\site-packages\bs4\dammit.py", line 13, in <module>
from html.entities import codepoint2name
File "D:\Automation\ReadHtml\html.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup' from 'bs4' (D:\Python37\lib\site-packages\bs4\__init__.py)
Edit:
I installed using
pip install BeautifulSoup4
also installed
pip install bs4
but it is still not working.

Soved Thanks, just renamed the file from html.py to something.py

Related

Why do i get this "Urllib" problems?

ok can someone explain why this code dosen't work
import urllib.request, urllib.parse, urllib.error
fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
counts = dict()
for line in fhand:
words = line.decode().split()
for word in words:
counts[word] = counts.get(word, 0) + 1
print(counts)
i get this traceback
Traceback (most recent call last):
File "C:\Users\boris\OneDrive\Desktop\python\urllib.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
File "C:\Users\boris\OneDrive\Desktop\python\urllib.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a package

Moviepy.editor import error "ImportError: cannot import name 'system'"

Hi so I'm trying to run this code to convert youtube videos into mp3 and download them using pytube and moviepy but I'm running into this:
File "C:/Users/KIIT/AppData/Local/Programs/Python/Python36/ydl2.py", line 2, in <module>
from moviepy.editor import system
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\editor.py", line 33, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 3, in <module>
from moviepy.video.VideoClip import VideoClip
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 14, in <module>
import proglog
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\proglog\__init__.py", line 5, in <module>
from .proglog import (ProgressLogger, ProgressBarLogger, TqdmProgressBarLogger,
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\proglog\proglog.py", line 4, in <module>
from tqdm import tqdm, tqdm_notebook
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\tqdm\__init__.py", line 1, in <module>
from ._tqdm import tqdm
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\tqdm\_tqdm.py", line 14, in <module>
from ._utils import _supports_unicode, _environ_cols_wrapper, _range, _unich, \
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\tqdm\_utils.py", line 3, in <module>
from platform import system as _curos
ImportError: cannot import name 'system'
Here's the code:
from pytube import YouTube
from moviepy.editor import system
from moviepy.editor import *
#convert to mp3 and download
youtube_link = 'https://www.youtube.com/watch?v=AaC6v0wCQWg'
y = YouTube(youtube_link)
t = y.streams.filter(only_audio=True).all()
t[0].download(output_path=r"..\Python\ydl2 songs")
Using pytube3 https://github.com/hbmartin/pytube3 you can use y.streams.get_audio_only()

ImportError: cannot import name 'StringIO'

I am trying to get data from yahoo of stocks of a company through the code.
But i am getting an ImportError at pandas_datareader.data where is says
ImportError: cannot import name 'StringIO'
Please help
I am new to this...and already spent 4 hrs but could not resolve.
I have even tried
import io
from io import StringIO
still getting the same error..!!
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
start = dt.datetime(2018,1,1)
end = dt.datetime(2018,12,31)
df = web.datareader('TSLA','yahoo',start,end)
print(df.head(5))
Error:-
Traceback (most recent call last):
File "C:\Users\JAILANCHAL\Desktop\tut.py", line 5, in <module>
import pandas_datareader.data as web
File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from pandas_datareader.av.forex import AVForexReader
File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\av\__init__.py", line 3, in <module>
from pandas_datareader.base import _BaseReader
File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\base.py", line 11, in <module>
from pandas.compat import StringIO, bytes_to_str
ImportError: cannot import name 'StringIO'

ImportError: cannot import name 'HTMLSession' from 'requests_html'

When I tried to use the new module requests_html using the example of its website,I found the console displays information in the title.
I have successfully installed requests_html using pip install requests_html
I have updated the python to python3.7 (64-bit)
The messages of console:
Traceback (most recent call last):
File "C:/Users/owlish/PycharmProjects/python34/requests.py", line 2, in <module>
from requests_html import HTMLSession
File "C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py", line 10, in <module>
import requests
File "C:\Users\owlish\PycharmProjects\python34\requests.py", line 2, in <module>
from requests_html import HTMLSession
ImportError: cannot import name 'HTMLSession' from 'requests_html' (C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py)
code:
from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://python.org/')
I expect it to work without an error,like the examples https://html.python-requests.org/.
With AhmedHawary's help,I found the reason for the error:I had a file named requests.py , which confilcted with the keywords . It worked fine after I renamed the file name.

ImportError: No module named url

when i run the the given code in prepare_dataset.py whose code is below as
from urllib.request
import urlopen
import json as simplejson
def main():
# Download and prepare datasets
list_generator = video_list_generator.Generator("playlists.json", youtube_api_client.Client("AIzaSyD_UC-FpXbJeWzPfscLz9RhqSjKwj33q6A"))
video_list = list_generator.get_video_list("piano")
downloader = youtube_video_downloader.Downloader()
downloader.download_from_list(video_list)
if __name__ == '__main__':
main()
as python prepare_dataset.py in command-line then i get these errors
Traceback (most recent call last):
File "prepare_dataset.py", line 1, in <module>
from urllib.request import urlopen
ImportError: No module named request
How can i get to run the above file any idea guys?

Resources