7

I am having a problem running a Python script and it is showing this message:

ImportError: No module named lxml

I suppose I have to install somewhat called lxml but I am really newbie to Python and I don't really have too much idea on that.

I think I have two versions of Python installed on my Mac from what I have read in other threads, but I am not sure.

How can I solve this issue?

Python Version: 2.7.6

Mac OS X 10.9.2

Alex
  • 517
  • 4
  • 9
  • 22
  • Finally I solved my problem using this command: `STATIC_DEPS=true pip install lxml` – Alex Mar 29 '14 at 13:16
  • Possible duplicate of [Cannot install Lxml on Mac os x 10.9](https://stackoverflow.com/questions/19548011/cannot-install-lxml-on-mac-os-x-10-9) – Nemo Jan 30 '18 at 16:15

2 Answers2

10

I've installed recently using pip, but before it would all work, I needed to issue the following command as instructed in this post:

xcode-select --install

If you don't have pip, you can get it from easy_install. If I recall correctly, the full sequence of commands should be something like this (assuming you already have gotten Xcode):

sudo easy_install pip
xcode-select --install
sudo pip install lxml
Community
  • 1
  • 1
mgilson
  • 300,191
  • 65
  • 633
  • 696
  • I am trying to install the command line developer tools via you first command but it says that the software can not be installed because it is not available in the upgrade's server. Also, I am trying to run the first line of your second code and it says that python version 2.7.6 can't run usr/bin/easy_install and it gives me three alternatives (python 2.5, 2.6 and 2.7). – Alex Mar 29 '14 at 11:34
  • It works for me, thank you very mach. Just would like to add t hat I did only the following steps: `xcode-select --install` `sudo pip install lxml` – Arsen Jan 21 '16 at 20:10
4

The answer of your question is here: http://lxml.de/installation.html#installation

Go to the MacOS section and follow the instructions :-)

Brice Argenson
  • 802
  • 2
  • 8
  • 13
  • I have tried to use this command: port install py25-lxml but it says the next: port:command not found – Alex Mar 27 '14 at 00:25
  • 1
    You have to install MacPort, it's not something available by default on MacOS. Otherwise, you can build it yourself using the Building lxml on MacOS-X section. – Brice Argenson Mar 27 '14 at 03:56