Hosts: ModuleNotFoundError: No module named 'lxml'

Created on 5 Aug 2020  Β·  6Comments  Β·  Source: StevenBlack/hosts

OS: macOS 10.15.6 (19G73)
Python version: 3.7.3

Hi, today I grabbed the latest from github and could not execute "updateHostsFile.py":

I ran: python3 ./updateHostsFile.py

The error:
Traceback (most recent call last):
File "testUpdateHostsFile.py", line 20, in
import updateHostsFile
File "/Users/username/Documents/github/hosts/updateHostsFile.py", line 24, in
import lxml # noqa: F401
ModuleNotFoundError: No module named 'lxml'

It appears that I have this module installed however. Is it perhaps not "seeing" my module because of a location or permissions issue?

Full log:

Last login: Wed Aug  5 14:20:52 on ttys000
β–‘β–’β–“  ~  cd Documents/github
β–‘β–’β–“  ~/Documents/github : git clone https://github.com/StevenBlack/hosts.git
Cloning into 'hosts'...
remote: Enumerating objects: 166, done.
remote: Counting objects: 100% (166/166), done.
remote: Compressing objects: 100% (100/100), done.
remote: Total 35805 (delta 92), reused 130 (delta 66), pack-reused 35639
Receiving objects: 100% (35805/35805), 131.97 MiB | 7.10 MiB/s, done.
Resolving deltas: 100% (21956/21956), done.
β–‘β–’β–“  ~/Documents/github : cd hosts
β–‘β–’β–“  ~/Documents/github/hosts : pip3 install --user -r requirements.txt
Requirement already satisfied: lxml<=5.0,>=4.2.4 in /usr/local/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (4.5.2)
Requirement already satisfied: beautifulsoup4<=5.0,>=4.6.1 in /usr/local/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (4.9.1)
Requirement already satisfied: flake8<=4.0,>=3.8 in /Users/username/Library/Python/3.8/lib/python/site-packages (from -r requirements.txt (line 3)) (3.8.3)
Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.8/site-packages (from beautifulsoup4<=5.0,>=4.6.1->-r requirements.txt (line 2)) (2.0.1)
Requirement already satisfied: pycodestyle<2.7.0,>=2.6.0a1 in /Users/username/Library/Python/3.8/lib/python/site-packages (from flake8<=4.0,>=3.8->-r requirements.txt (line 3)) (2.6.0)
Requirement already satisfied: pyflakes<2.3.0,>=2.2.0 in /Users/username/Library/Python/3.8/lib/python/site-packages (from flake8<=4.0,>=3.8->-r requirements.txt (line 3)) (2.2.0)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /Users/username/Library/Python/3.8/lib/python/site-packages (from flake8<=4.0,>=3.8->-r requirements.txt (line 3)) (0.6.1)
β–‘β–’β–“  ~/Documents/github/hosts : python3 testUpdateHostsFile.py
Traceback (most recent call last):
  File "testUpdateHostsFile.py", line 20, in <module>
    import updateHostsFile
  File "/Users/username/Documents/github/hosts/updateHostsFile.py", line 24, in <module>
    import lxml  # noqa: F401
ModuleNotFoundError: No module named 'lxml'
β–‘β–’β–“  ~/Doc/github/hosts : pip3 list
Package        Version
-------------- -------
beautifulsoup4 4.9.1
bs4            0.0.1
flake8         3.8.3
lxml           4.5.2
mat2           0.11.0
mccabe         0.6.1
pip            20.2.1
pycairo        1.19.1
pycodestyle    2.6.0
pyflakes       2.2.0
PyGObject      3.36.1
setuptools     49.2.1
soupsieve      2.0.1
wheel          0.34.2

Most helpful comment

@ankushduacodes thank you so much!
Something in the last week must have changed the instance of python3 that was my "default"

I couldn't track down the cause but I reinstalled a few packages and everything is back to normal now!
I understand that this was not related to the project here. Thank you both for the help in getting this resolved.

All 6 comments

Hello! Thank you for opening your first issue in this repo. It’s people like you who make these host files better!

I'm guessing that the following will fix this.

pip3 install --user -r requirements.txt

Ahh I already ran that in the big log up above but I ran it again today and it's still throwing me the same lxml module error.

Screen_Shot_2020-08-06_at_17_25_38

it might be an issue with the which python interpreter you are using to compile it, if you look closely your computer has 2 or more python interpreter installed(if you run where python3 in your terminal it will give you the list and paths of python interpreters installed on your computer).
lxml module was installed in /usr/local/lib/python3.8/site-packages and that is also true for beautifulsoup4 but for all other packages the installation path is in Library folder.

one thing you can do is open vs code and paste this next statement #!usr/bin/python on the the first line of this file which will then give you a prompt to change your interpreter and click select as interpreter then again run pip3 install -r requirements.txt in the vs code terminal and then try running the desired file.
i hope this solves your problem

@ankushduacodes thank you so much!
Something in the last week must have changed the instance of python3 that was my "default"

I couldn't track down the cause but I reinstalled a few packages and everything is back to normal now!
I understand that this was not related to the project here. Thank you both for the help in getting this resolved.

I am glad that its fixed.
I hope you have a great day.

Was this page helpful?
0 / 5 - 0 ratings