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.

2
  • 3
    Since you are using python3, you should use pip3 install lxml Commented May 16, 2019 at 17:45
  • 1
    Hi Nithin, that worked thanks so much. Commented May 16, 2019 at 17:52

4 Answers 4

5

Try upgrading. pip install --upgrade lxml

Sign up to request clarification or add additional context in comments.

1 Comment

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
1

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

1 Comment

It is a comment not an answer. Please read this document stackoverflow.com/help/how-to-answer
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)

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.