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
Related
I have made a few projects which run fine. A new project required me to install pip install cbpro (a module for dealing with coinbase cryptocurrency API).
After installing it, even running the simplest code throws several errors:
Input:
import cbpro
import pandas as pd
c = cbpro.PublicClient()
data = pd.DataFrame(c.get_products())
data.tail().T
Errors:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/stonks/coinbase_interface.py", line 1, in <module>
import cbpro
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cbpro/__init__.py", line 1, in <module>
from cbpro.authenticated_client import AuthenticatedClient
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cbpro/authenticated_client.py", line 10, in <module>
import requests
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 29, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 174, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Secondly, when I then go to other projects that were working well, I get additional errors. Of note, those projects start with:
import pandas as pd
import requests
import json
Errors:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/stonks/historical_crypto_pull.py", line 2, in <module>
import requests
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 29, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 174, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Things I've tried:
If I uninstall cbpro, then uninstall and reinstall requests, I can undo the error and am back where I started. However, I'm interested in knowing why I am encountering these errors because I'd like to actually use cbpro and know how to solve this issue in the future.
The libraries I was using were not compatible with Python 3.10. I am still at a loss for how I would inherently know that based on the errors thrown, but since then my solution was to install Python 3.9 and see if I still get the same errors when running 3.9.
(Then I also read that it might be a better idea for my current purposes to use a slightly older version of Python, so I moved over to 3.9 completely and haven't had the same issue again.)
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.
I'm trying to start with ANTLR . When I import module antlr it's working just fine , but if I try to import MyGrammarLexer and MyGrammarParser , it's shows that MyGrammarLexer and Parser aren't in lib. I Using PyCharm , I installed ANTLR with : pip3 install antlr4-python3-runtime my code is :
import sys
from antlr4 import *
import MyGrammarLexer
import MyGrammarParser
def main(argv):
input = FileStream(argv[1])
lexer = MyGrammarLexer(input)
stream = CommonTokenStream(lexer)
parser = MyGrammarParser(stream)
tree = parser.startRule()
if __name__ == '__main__':
main(sys.argv)
Maybe whom know why i can't import MyGrammarLexer and MyGrammarParser?
Please suggest!
Tackback:
/usr/bin/python3.6 /home/andrejka/PycharmProjects/Parser/parser.py
Traceback (most recent call last):
File "/home/andrejka/PycharmProjects/Parser/parser.py", line 2, in <module>
from antlr4 import *
File "/usr/lib/python3/dist-packages/antlr4/__init__.py", line 5, in <module>
from antlr4.BufferedTokenStream import TokenStream
File "/usr/lib/python3/dist-packages/antlr4/BufferedTokenStream.py", line 19, in <module>
from antlr4.error.Errors import IllegalStateException
File "/usr/lib/python3/dist-packages/antlr4/error/Errors.py", line 5, in <module>
from antlr4.atn.Transition import PredicateTransition
File "/usr/lib/python3/dist-packages/antlr4/atn/Transition.py", line 19, in <module>
from __builtin__ import unicode
ModuleNotFoundError: No module named '__builtin__'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "/home/andrejka/PycharmProjects/Parser/parser.py", line 2, in <module>
from antlr4 import *
File "/usr/lib/python3/dist-packages/antlr4/__init__.py", line 5, in <module>
from antlr4.BufferedTokenStream import TokenStream
File "/usr/lib/python3/dist-packages/antlr4/BufferedTokenStream.py", line 19, in <module>
from antlr4.error.Errors import IllegalStateException
File "/usr/lib/python3/dist-packages/antlr4/error/Errors.py", line 5, in <module>
from antlr4.atn.Transition import PredicateTransition
File "/usr/lib/python3/dist-packages/antlr4/atn/Transition.py", line 19, in <module>
from __builtin__ import unicode
ModuleNotFoundError: No module named '__builtin__'
I ran into this problem recently when getting the same error using the pddlpy python library. I was able to fix it by doing the following:
pip3 install antlr4-python3-runtime==4.9
The version 4.9 at the end is very important.
I found out that content of the package:
https://pypi.python.org/packages/0b/6b/30c5b84d203b62e1412d14622e3bae6273399d79d20f3a24c8145213f610/antlr4-python3-runtime-4.7.tar.gz#md5=190245a0fb4abf43568489a4b6e33aba
is different from the package installed by pip3.
I have replaced content of:
~/anaconda3/envs/py3/lib/python3.6/site-packages/antlr4
with content from the package I have downloaded and extracted manually:
~/Downloads/antlr4-python3-runtime-4.7/src/antlr4
It seems to be working now - in particular the following error:
ModuleNotFoundError: No module named '__builtin__'
does not occur.
After posting your traceback I can see the error is:
ModuleNotFoundError: No module named '__builtin__'
That means the package you try to import is using python2 syntax, but you're using python3.
You should use python2 if you need to run this package, but keep in mind that you probably want to search for a different one if this is a new project.
More about why it's not working here
EDIT
They released a package with python3 support, but it seems you installed/used something different. You should verify it.
I use Python 3.2.3
Tonight I tried to install requests from http://docs.python-requests.org/en/latest/ by pip and easy_install, but it doesn't work. I have error when trying to import it. So I decided to use standard library urllib.request and see this error again
That is the traceback:
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\Python32\lib\site-packages\requests-1.2.0-py3.2.egg\requests\__init__.py", line 52, in <module>
from . import utils
File "E:\Python32\lib\site-packages\requests-1.2.0-py3.2.egg\requests\utils.py", line 12, in <module>
import cgi
File "E:\Python32\lib\cgi.py", line 38, in <module>
from email.parser import FeedParser
File "E:\Python32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser
File "E:\Python32\lib\email\feedparser.py", line 27, in <module>
from email import message
File "E:\Python32\lib\email\message.py", line 17, in <module>
from email import utils
File "E:\Python32\lib\email\utils.py", line 28, in <module>
import socket
File "E:\Python32\lib\socket.py", line 46, in <module>
import _socket
ImportError: Module use of python26.dll conflicts with this version of Python.
So how can I fix this?
UPD: Solved. It was bug in SublimeREPL, reinstalled that package.
I had a similar problem when I was using PythonXY. The Spyder was not loading and it turns out another software OpenCAD had installed Python2.6 version and that was not letting my Python27.dll to not work. After uninstalling OpenCAD, I was able to run the software.
I was able to troubleshoot by first searching for python26.dll and found that this file was located in the OpenCAD folder location and that made me realize that this software was causing the issue.
I am programming in Python 3.3 on the latest version of Ubuntu. I am writing code for a project involving a library that works with Twitter. Here is the output from the terminal I have:
Traceback (most recent call last):
File "tryout.py", line 2, in <module>
import twitter
File "/home/owner/Documents/twitter/__init__.py", line 15, in <module>
from .stream import TwitterStream
File "/home/owner/Documents/twitter/stream.py", line 9, in <module>
from ssl import SSLError
File "/usr/local/lib/python3.3/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named '_ssl'
I've been looking around to find a solution for the _ssl error but can't seem to find one that I could follow.