Brent Heigold
Brent Heigold

Reputation: 1273

Python 3 - getting "No module named 'lxml' " after installing lxml with pip (non-root)

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.

Upvotes: 5

Views: 17686

Answers (4)

Pavel12398
Pavel12398

Reputation: 57

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

Upvotes: 0

Turk Data Lab
Turk Data Lab

Reputation: 51

Try upgrading. pip install --upgrade lxml

Upvotes: 5

ssrini20
ssrini20

Reputation: 1

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)

Upvotes: 0

Jeremias Pereira
Jeremias Pereira

Reputation: 11

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

Upvotes: 1

Related Questions