Errors importing BeautifulSoup4 - python

I am trying to import BeautifulSoup4, but am running into importation issues.
I am running Python 2.7.9 as 32 bit Windows (MSC v.1500)
I attempted to install BeautifulSoup4 as both a tarball and using pip. Both attempts have "installed" bs4, but import bs4 yields:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\ArcGIS10.2\lib\site-packages\bs4\__init__.py", line 29, in <module>
from .builder import builder_registry
File "C:\Python27\ArcGIS10.2\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
from . import _htmlparser
File "C:\Python27\ArcGIS10.2\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
from HTMLParser import (
File "C:\Python27\ArcGIS10.2\lib\HTMLParser.py", line 47, in <module>
""", re.VERBOSE)
File "C:\Python27\ArcGIS10.2\lib\re.py", line 190, in compile
return _compile(pattern, flags)
File "C:\Python27\ArcGIS10.2\lib\re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
I have no idea how to fix this. Any help would be appreciated.

Try:
from bs4 import BeautifulSoup

Related

when importing web3 in python getting error

I am trying to execute the "import web3" statement in python console and getting the following error.
EDIT: I am using Python 3.9.0a1 and pip 21.3.1.
I have tried doing it both in VSCode terminal and windows command prompt.
>>> import web3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\__init__.py", line 9, in <module>
from web3.main import (
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\main.py", line 87, in <module>
from web3.manager import (
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\manager.py", line 47, in <module>
from web3.providers import (
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\providers\__init__.py", line 8, in <module>
from .rpc import ( # noqa: F401,
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\providers\rpc.py", line 21, in <module>
from web3._utils.request import (
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\_utils\request.py", line 6, in <module>
from aiohttp import (
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\__init__.py", line 6, in <module>
from .client import (
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\client.py", line 35, in <module>
from . import hdrs, http, payload
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\http.py", line 7, in <module>
from .http_parser import (
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\http_parser.py", line 15, in <module>
from .helpers import NO_EXTENSIONS, BaseTimerContext
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\helpers.py", line 48, in <module>
from typing_extensions import Protocol
File "C:\Users\f1cmpica-1\AppData\Local\Programs\Python\Python39\lib\site-packages\typing_extensions.py", line 2142, in <module>
def TypeAlias(self, parameters):
TypeError: __init__() missing 1 required positional argument: 'doc'
You mentioned no version numbers.
https://stackoverflow.com/help/minimal-reproducible-example
I installed these from conda-forge, with interpreter 3.9.7 on MacOS 12.0.1:
typing-extensions 4.0.1
web3 5.26.0
And then import web3 works Just Fine.

Glitch in html5lib?

I'm getting this error. Is it a bug or is it a code error? What does it mean?
Traceback (most recent call last):
File "isc.py", line 8, in <module>
import requests, os, sys, bs4
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/bs4/__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/bs4/builder/__init__.py", line 314, in <module>
from . import _html5lib
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/bs4/builder/_html5lib.py", line 70, in <module>
class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
AttributeError: module 'html5lib.treebuilders' has no attribute '_base'
(i upgraded html5lib bs4 and requests)
It's an issue related to your html5lib package version try upgrading it.

Getting "ImportError: cannot import name 'HTMLParseError' from 'html.parser'" with bs4

I'm on windows 10 using python 3.8.2 and got this problem when I try to run from bs4 import BeautifulSoup I get the following:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Cesar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\bs4\__init__.py", line 29, in <module>
from .builder import builder_registry
File "C:\Users\Cesar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
from . import _htmlparser
File "C:\Users\Cesar\AppData\Local\Programs\Python\Python38-32\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\Cesar\AppData\Local\Programs\Python\Python38-32\lib\html\parser.py)
>>>
I've install and uninstall bs4 several times and still got the same error
what would you recommend?

Error in importing requests module in python3

I am using requests module in my python program. It worked great in the previous day. But now, when importing requests module, it is showing a weird error. It is working great in python2 version. But shows error in python3. I googled it but can't find a solution. I haven't changed anything. Why it is showing this error.
Here it is:
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/paulsteven/.local/lib/python3.5/site-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/home/paulsteven/.local/lib/python3.5/site-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/home/paulsteven/.local/lib/python3.5/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/home/paulsteven/.local/lib/python3.5/site-packages/OpenSSL/rand.py", line 11, in <module>
from OpenSSL._util import (
File "/home/paulsteven/.local/lib/python3.5/site-packages/OpenSSL/_util.py", line 3, in <module>
from cryptography.hazmat.bindings.openssl.binding import Binding
File "/home/paulsteven/.local/lib/python3.5/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 188, in <module>
_verify_package_version(cryptography.__version__)
File "/home/paulsteven/.local/lib/python3.5/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 175, in _verify_package_version
so_package_version = ffi.string(lib.CRYPTOGRAPHY_PACKAGE_VERSION)
AttributeError: cffi library '_openssl' has no function, constant or global variable named 'CRYPTOGRAPHY_PACKAGE_VERSION'
Reinstalling cryptography package will resolve this problem.

Unable to install pip on windows for python 3.6.1 version

I am getting the below error while using the command:
python get-pip.py
Error:
c:\Python>python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
File "C:\Users\dell\AppData\Local\Temp\tmpa0q8wceq\pip.zip\pip\__init__.py", l
ine 26, in <module>
File "C:\Users\dell\AppData\Local\Temp\tmpa0q8wceq\pip.zip\pip\utils\__init__.
py", line 27, in <module>
File "C:\Users\dell\AppData\Local\Temp\tmpa0q8wceq\pip.zip\pip\_vendor\pkg_res
ources\__init__.py", line 35, in <module>
File "c:\Python\lib\plistlib.py", line 65, in <module>
from xml.parsers.expat import ParserCreate
File "c:\Python\lib\xml\parsers\expat.py", line 4, in <module>
from pyexpat import *
ImportError: DLL load failed: The specified module could not be found.
I'm pretty sure that pip comes with python 3 and up. If you have troubles running only "pip" from the terminal i'd recommend you try: python -m pip ...
Try to use the 'Alternative instructions' from this post.
Hope this can help.

Categories