5

I just want to say, I have already seen this question at Pip is already installed: but I am getting no module named lxml and have seen the one answer about installing it as non-root, that's what I did, and that did not help me.

I just installed lxml, here is how I installed it:

[ec2-user@ip-xxx-xx-xx-xxx newslookup]$ pip install --user lxml
Collecting lxml
  Using cached https://files.pythonhosted.org/packages/89/51/a8a6cdb8a084d32dbc9bda94623dc35310ae2002be57de8702a1703c0026/lxml-4.3.3-cp27-cp27mu-manylinux1_x86_64.whl
Installing collected packages: lxml
Successfully installed lxml-4.3.3

So everything went well with the installation.

Here is the python script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from lxml import html
import requests
from time import sleep
import json
import argparse
from random import randint

Here is the output when I run the script:

[ec2-user@ip-xxx-xx-xx-xxx newslookup]$ python3 nasdaq_scrape_sec.py aapl
Traceback (most recent call last):
  File "nasdaq_scrape_sec.py", line 4, in <module>
    from lxml import html
ModuleNotFoundError: No module named 'lxml'

Additionally, I can't find a wheel installation for this.

Brent Heigold
  • 1,213
  • 5
  • 24
  • 50

4 Answers4

4

Try upgrading. pip install --upgrade lxml

Timbus Calin
  • 13,809
  • 5
  • 41
  • 59
  • This worked for me. It seems that installing lxml is not enough. After installing it you have to upgrade it. I am working with python 3.9.5 – Corina Roca Jul 21 '22 at 14:54
1

what version python you are use, you are use python2.7 install how pip else python3 you should usar pip3

  • It is a comment not an answer. Please read this document https://stackoverflow.com/help/how-to-answer – Ashkan S May 16 '19 at 23:33
0

In my case in windows, this happened as I had multiple python.exe instances installed. Package was installed on one instance, but running the script used the other one. So you want to run the specific python.exe instance where the pip was installed. You can find out where it is installed by trying to install the same package twice. Second time it gives you a message like this:

Requirement already satisfied: lxml in c:\users\blahuser\appdata\local\programs\python\python36-32\lib\site-packages (4.3.4)

Check this related post for more info: ModuleNotFoundError: No module named 'requests' after pip install

You should be able to run successfully with a commnad line this:

c:\Users\blahuser\AppData\Local\Programs\Python\Python36-32\python.exe c:\test\scripts\blah.py

I guess you can also fix the environment variables to trigger the right python.exe to start with and the issue will go away too, or even force install the pip on the default instance of python (See the link above)

0

I had a similar problem and I solved it

in my code it was

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

I replaced all the files with this

#!/usr/bin/env python
# -*- coding: utf-8 -*-

try to remove this line maybe it will help you

Pavel12398
  • 47
  • 6