ModuleNotFoundError: No module named 'bs4' even after installing and re-installing - python

I'm trying to run my Python file. (py name.py)
from bs4 import BeautifulSoup as BS
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\__init__.py", line 29, in <module>
from .builder import builder_registry
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
from . import _htmlparser
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
from html.parser import (
ImportError: cannot import name 'HTMLParseError' from 'html.parser' (C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\html\parser.py)
I installed this library using "pip".
After the library is completely removed and installed again, this error appears when you run this code.
File "name.py", line 9, in <module>
from bs4 import BeautifulSoup as BS
ModuleNotFoundError: No module named 'bs4'

I solved the problem. First I deleted all BS4 mentions from my PC. Then in CMD moved on path:
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts.
And spent there the command:
pip install beautifulsoup4

Related

cannot import name 'etree' from 'lxml' in home brew installed package but fine in python shell

I'm trying to run ocrmypdf which was installed via homebrew but am having issues with my local version of lxml (version 4.2.4):
Traceback (most recent call last):
File "/usr/local/bin/ocrmypdf", line 5, in <module>
from ocrmypdf.__main__ import run
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/ocrmypdf/__init__.py", line 18, in <module>
from . import helpers, hocrtransform, leptonica, pdfa, pdfinfo
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/ocrmypdf/pdfa.py", line 38, in <module>
import pikepdf
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/__init__.py", line 54, in <module>
from .models import (
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/models/__init__.py", line 13, in <module>
from .metadata import PdfMetadata
File "/usr/local/Cellar/ocrmypdf/9.8.2/libexec/lib/python3.8/site-packages/pikepdf/models/metadata.py", line 17, in <module>
from lxml import etree
ImportError: cannot import name 'etree' from 'lxml' ($HOME/anaconda3/lib/python3.7/site-packages/lxml/__init__.py)
If I open up a python shell, I'm able to import just fine:
>>> from lxml import etree
>>> etree.__file__
'$HOME/anaconda3/lib/python3.7/site-packages/lxml/etree.cpython-37m-darwin.so'
My pythonpath:
$HOME/anaconda3/lib/python3.7/site-packages:$HOME/Code_Repos/invoice2data//src:$HOME/Code_Repos/invoice2data//src/invoice2data:$HOME/anaconda3/lib/python3.7/site-packages:$HOME/Code_Repos/invoice2data
I'm not sure why the homebrewed package is not picking up the module file even though it says it's pointing to the same site-packages folder.

Installing beautifulsoup

I have installed beautifulsoup for Python, but it gives me this error when I import the library:
Traceback (most recent call last):
File "D:/Playroom/WebScraper_01.py", line 2, in <module>
from bs4 import BeautifulSoup
File "C:\Python\lib\site-packages\bs4\__init__.py", line 29, in <module>
from .builder import builder_registry
File "C:\Python\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
from . import _htmlparser
File "C:\Python\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
from html.parser import (
ImportError: cannot import name 'HTMLParseError'
Does anyone know why?
If you get the ImportError “No module named HTMLParser”, your problem is that you’re running the Python 2 version of the code under Python 3.
If you get the ImportError “No module named html.parser”, your problem is that you’re running the Python 3 version of the code under Python 2.
See: https://www.crummy.com/software/BeautifulSoup/bs4/doc/#problems-after-installation

ImportError from python-fitbit

I'm trying to use the python-fitbit package with Python 3.4 to get information from Fitbit (https://github.com/orcasgit/python-fitbit).
Whenever I run it, I get the following error. Right now oauthlib is installed, and I've tried uninstalling and reinstalling it to no avail. Any thoughts would be appreciated.
File "/usr/local/lib/python3.4/dist-packages/fitbit/__init__.py", line 10, in <module>
from .api import Fitbit, FitbitOauth2Client
File "/usr/local/lib/python3.4/dist-packages/fitbit/api.py", line 12, in <module>
from requests_oauthlib import OAuth2, OAuth2Session
File "/usr/local/lib/python3.4/dist-packages/requests_oauthlib/__init__.py", line 1, in <module>
from .oauth1_auth import OAuth1
File "/usr/local/lib/python3.4/dist-packages/requests_oauthlib/oauth1_auth.py", line 6, in <module>
from oauthlib.common import extract_params
ImportError: No module named 'oauthlib'
Where in your file system did you install oauthlib?
Please make sure that oauthlib is in your python path.
In order to check your python path you can execute:
import sys; print sys.path

Import error urllib.parse in scrapy

I am trying to use scrapy. I did pip install scrapy. My python version is 2.7.9. After installing when I typed scrapy in the terminal it gave the following error:
File "/usr/bin/scrapy", line 7, in <module>
from scrapy.cmdline import execute
File "/usr/lib/python2.7/site-packages/scrapy/__init__.py", line 48, in <module>
from scrapy.spiders import Spider
File "/usr/lib/python2.7/site-packages/scrapy/spiders/__init__.py", line 10, in <module>
from scrapy.http import Request
File "/usr/lib/python2.7/site-packages/scrapy/http/__init__.py", line 10, in <module>
from scrapy.http.request import Request
File "/usr/lib/python2.7/site-packages/scrapy/http/request/__init__.py", line 12, in <module>
from scrapy.utils.url import escape_ajax
File "/usr/lib/python2.7/site-packages/scrapy/utils/url.py", line 9, in <module>
from six.moves.urllib.parse import (ParseResult, urlunparse, urldefrag,
ImportError: No module named urllib.parse
I know scrapy needs python 2.7 but urllib.parse is introduced in python 3, before that it was urlparse. Looking at the error it seems the error is in the scrapy installation. What to do? I have uninstalled and reinstalled scrappy several times. But the problem is still there.
We can use seperate imports for python 2 and python 3.
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
Got this answer from here.
no module named urllib.parse (How should I install it?)

ImportError: No module named bs4 how fix

I have next python 2.7 (debian) code
import sys
import random
from bs4 import BeautifulSoup
from YandexDiskException import YandexDiskException
from YandexDiskRestClient import YandexDiskRestClient
I try run, but get this message
root#vps-1074211:/tmp/beautifulsoup4-4.4.0# python /var/vah13/untitled/grep.py
Traceback (most recent call last):
File "/var/vah13/untitled/grep.py", line 5, in <module>
from bs4 import BeautifulSoup
ImportError: No module named bs4
how fix it?
I installed
pip install beautifulsoup4
apt-get install python-bs4

Categories

Resources