"Python 3.5 successfully incorporates Html5Lib, while it is not supported in the 2.7

An error has been troubling me recently:

Traceback (most recent call last):
  File "scrapeRecipe.py", line 29, in <module>
    br.select_form(name="aspnetForm")
  File "build/bdist.macosx-10.11-intel/egg/mechanize/_mechanize.py", line 619, in select_form
  File "build/bdist.macosx-10.11-intel/egg/mechanize/_html.py", line 260, in global_form
  File "build/bdist.macosx-10.11-intel/egg/mechanize/_html.py", line 267, in forms
  File "build/bdist.macosx-10.11-intel/egg/mechanize/_html.py", line 282, in _get_forms
  File "build/bdist.macosx-10.11-intel/egg/mechanize/_html.py", line 247, in root
  File "build/bdist.macosx-10.11-intel/egg/mechanize/_html.py", line 145, in content_parser
ImportError: No module named html5lib

I'm curious as to why the Traceback is referencing these files. Additionally, when I use

locate build/bdist.macosx-10.11-intel/egg/mechanize/_mechanize.py
, it claims that the file doesn't exist.

I suspect that the reason for this missing module error is due to the fact that the html5lib module is situated in

/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/_vendor/html5lib
.

Question: Is there a way to influence where the traceback looks? Furthermore, my sys.path currently contains:

['/Users/madelinezechar/eatLowCarbon', '/Library/Python/2.7/site-
packages/BeautifulSoup-3.2.1-py2.7.egg', '/Library/Python/2.7/site-
packages/html2text-2016.9.19-py2.7.egg', '/Library/Python/2.7/site-
packages/mechanize-0.3.1-py2.7.egg', '/Library/Python/2.7/site-
packages/requests-2.13.0-py2.7.egg', '/Library/Python/2.7/site-
packages/pip-9.0.1-py2.7.egg', 
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',     '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',     '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',     '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',   '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',     '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', 
'/Users/madelinezechar/Library/Python/2.7/lib/python/site-packages',     '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', 
'/Library/Python/2.7/site-packages']

I installed html5lib using easy_install html5lib. After installation, running it displayed the following message:

Adding html5lib 0.999999999 to easy-install.pth file

Using /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages
Processing dependencies for html5lib
Finished processing dependencies for html5lib

I am worried about it referencing Python 3.5 even though my sys.path points to 2.7 and my python code runs on 2.7. Additionally, post-installation, html5lib isn't present in easy_install.pth:

import sys; sys.__plen = len(sys.path)

 ./BeautifulSoup-3.2.1-py2.7.egg
   ./html2text-2016.9.19-py2.7.egg
   ./mechanize-0.3.1-py2.7.egg
   ./requests-2.13.0-py2.7.egg
   ./pip-9.0.1-py2.7.egg
   import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)

Upon checking pip3 freeze, I found html5lib listed. However, it doesn't appear with pip freeze. Trying sudo pip install html5lib resulted in an error:

https://i.stack.imgur.com/0rtUV.jpg

What does this error signify? How can it be that pip freeze doesn't show html5lib while I'm certain that html5lib.py exists in

Python/2.7/site-packages/bs4/builder
?

Answer №1

When facing a different error with installing html5lib for python 2.7, I found a solution that worked for me:

pip install --ignore-installed six --user
sudo -H pip install html5lib --ignore-installed

If you want to delve deeper into this topic, I recommend checking out this insightful discussion: https://github.com/pypa/pip/issues/3165

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Difficulty accessing CSV files in Pandas due to KeyError

I have successfully used pandas to create a CSV file, but I encountered an error during the process: Traceback (most recent call last): File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas ...

Failed to find the element using Selenium

Can anyone help me find the username input section on the following website: ? I've included the code snippet I used below: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import ...

Converting weather station data into a dataframe using Python and storing it in a Postgresql database

How can I organize the data retrieved from an API query into a table with column names and cell values? wea_data = [{'observation_time': '2023-05-09T15:55:00.000000+00:00', 'station': 'KCOF', 'we ...

When PyCharm is not in debug mode, it runs smoothly without any issues, but as soon as debug

UPDATE: After reverting back to PyCharm version 2017.2.4, the script started working again. It seems that the issue was with the IDE and not the script itself. Recently, my script has been running smoothly until today. Strangely, it only runs without any ...

Interacting with Discord Using Selenium in Python

Greetings, I am encountering a problem with the code snippet below. The specific issue is that after opening a submenu and attempting to send down arrow keys, it does not work properly unless I use a multiplier like *100. Any assistance on this matter wo ...

"Djoser encounters a 400 Bad Request error when attempting to log in users

Currently working on an e-commerce application using django rest framework and vue. Utilizing djoser.authtoken for authentication purposes. Successfully managed to create a user with a POST request to /users/, but encountering issues while attempting to l ...

The performance of the Python 2.7 DDos Script leaves much to be desired due

Currently, I am experimenting with creating a DDos Script for educational purposes. However, I have encountered a setback as it is operating at a slower pace and utilizing only around 0.8Mb of my upload speed out of the available 20Mb. UPDATE 3 To addres ...

How can I use XPATH and Python Selenium to select the text node that is outside of an <a> element?

Check out the following link: Within this section of code: //*[@id="main-contents"]/div[1]/table[1]/tbody/tr/td, there is a piece of text Mottled Boar slain (10) //*[@id="main-contents"]/div[1]/table[1]/tbody/tr/td/a This part contains only: Mo ...

Experiencing a '429 error: excessive requests' while utilizing Instagram API through a Python script

I am attempting to execute a script that logs into Instagram and uploads 10 images with randomly generated text on them. However, the following is the output I receive when trying to run the script: 2023-01-02 21:56:48,608 - INFO - Instabot version: 0.117. ...

resizing opencv and altering RGB colors

When using opencv's resize function, I've noticed that the image tends to get blurred after resizing up and down. Is there a way to prevent this blurring effect and maintain image clarity? I suspect this issue may be related to sampling problems. ...

Updating an image using AJAX and Flask

I have a situation in HTML where I need to constantly update an image file with the latest images that come in. Below is the Flask code snippet: @app.route('/uploads/update_file', methods=['GET', 'POST']) def update_file(): ...

Encountering a coding issue in Arabic when utilizing the requests RESTful client

Below is a Python code snippet for a RESTful client: import requests; s= 'This is the message to be sent'; resp = requests.post('http://localhost:8080/MyApp/webresources/production/sendMessage', json={'message': s,} ) This c ...

Sending a variety of metadata tags using keyword arguments from a variable

I am attempting to pass metadata tags that were generated through code. import ffmpeg tags = {'metadata:g:0':"artist=various artists", 'metadata:g:1':"title=title" , 'metadata:g:2':"network=network", 'metadata:g:3&a ...

The error encountered is a NameError, specifically stating that the name '<name>' has not been defined when attempting to use the % format syntax for strings

Traceback (most recent call last): File "C:\Users\Simon\Downloads\rpgbs.py", line 72, in <module> print("%(chara) has %(health) HP." % {chara:names[k], health:str(health[k])}) NameError: name 'chara' is not defined ...

Transforming JSON data into string format

Looking for a way to convert the JSON below into a fully string-quoted JSON format using Python. Is there a method in the python "json" module that can help with this, or is there a simpler parsing code available? Original data: data = '[{"id":334," ...

Remove rows from a pandas dataframe based on a specified list

I need assistance with filtering a dataframe that contains a column of countries and other irrelevant variables. I have provided a sample dataset below: data = {"country": ["AA", "BB", "AA", "CC", "DD", "AA", "BB", "AA", "CC", "DD"], "other variable": ["f ...

Preventing .toml file corruption during power outages using Python

My small Python program fetches data from a website and saves it into a TOML file to easily access the string. Unfortunately, one time while running the script, there was a power outage, and when I turned my computer back on, the file was filled with "null ...

What should you do to move to the next line or block if a specific element cannot be located?

Hello there, I am Hugo. Currently, I am scraping a website that lacks a 'next page' button. To navigate through the pages, I am manually changing the page number in the URL. I have implemented a loop to cycle through a list of URLs within the cod ...

Pop-up warning - endless search cycle

As a novice, my question might be a bit strange :) I want to test the Main Menu of the website "https://tvn24.pl/" I am searching for elements, adding them to a list, and then iterating through each one to open every discovered page - everything is worki ...

What is the best way to search for a specific word within a list of sentences, but only focusing on the first word of each sentence?

list = ["This is an example", "Hello there! This is an example"] search = input("Enter keyword: ") for title in list: if search in title: print(title) #Output Search: This This is an example Hello there! This i ...