6

Tried various avenues but no luck. I am using a MBP with 10.7.4. I don't remember the last time I had so many problems installing anything with Python on my Mac. Please help me use lxml on my local machine and not rely on SVN commits, updates to remotely run on the Linux machine.

$ sudo STATIC_DEPS=true /usr/bin/easy_install-2.7 lxml
Password:
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3.4
Downloading http://lxml.de/files/lxml-2.3.4.tgz
Processing lxml-2.3.4.tgz
Running lxml-2.3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mbyEtk/lxml-2.3.4/egg-dist-tmp-O_t_3P
Building lxml version 2.3.4.
Latest version of libiconv is 1.14
Downloading libiconv into libs/libiconv-1.14.tar.gz
error: [Errno 60] Operation timed out

Tried the following with no luck

$ python setup.py build

$ STATIC_DEPS=true sudo easy_install --allow-hosts=lxml.de,*.python.org lxml
$ sudo pip install lxml

llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/usr/include/libxml2 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.7-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespace

unable to execute llvm-gcc-4.2: No such file or directory

error: command 'llvm-gcc-4.2' failed with exit status 1
ThinkCode
  • 7,841
  • 21
  • 73
  • 92
  • what does your `~/.pip/pip.log` say? – mata May 19 '12 at 15:44
  • @mata : -bash: /Users/ThinkCode/.pip/pip.log: No such file or directory – ThinkCode May 19 '12 at 15:49
  • @ThinkCode - if you're run pip as root then the log should be in `/root/.pip/pip.log`. but as @larsks pointed out, you need to make sure to have gcc installed and in your `$PATH`. – mata May 19 '12 at 16:08

3 Answers3

7

I first installed MacPorts and then:

$ sudo port install python27 py27-lxml

And this gave me a functioning lxml installation.

Regarding your error messages, you appear to be missing the compiler command that pip is using to build lxml (llvm-gcc-4.2). Do you have the OS X development tools installed? You should find that file in /usr/bin/llvm-gcc-4.2; if it's not there, you probably need to download and install the development package.

You can install the XCode developer tools via the App Store. If you read the comments in the app store, you'll note that in order to make the command line tools available you need to install them separately. In XCode, go to Preferences->Downloads and download the "Command line tools" package.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Can I install it without MacPorts? – ThinkCode May 19 '12 at 15:39
  • 1
    Sure, it's possible. But in general I would rather spend my time *using* the software, so I'm happy to take advantage of things that make it easier to *install* the software. – larsks May 19 '12 at 15:40
  • I will wait for any other answers and I will eventually resort to MacPorts if I don't get anywhere with lxml install. Thanks much. Upvoted. – ThinkCode May 19 '12 at 15:42
  • I have XCode installed already. With PIP, it complained about Cython. I don't have llvm-gcc-4.2 in /usr/bin. – ThinkCode May 19 '12 at 15:47
  • 3
    Yeah, you're missing the command line tools. See my update. This is apparently a recent change -- older versions of XCode Just Worked. – larsks May 19 '12 at 16:10
  • 1
    'sudo pip install lxml' did the trick after I installed 'Command line tools'. 'sudo port install python27 py27-lxml' gave an error though (Error: Processing of port python27 failed). I am still choosing this answer. Thanks for the 'Command Line tools' suggestion. Thank you Apple for not installing them by default ;) – ThinkCode May 19 '12 at 16:27
  • damn macports took forever to install! – pythonian29033 Dec 10 '13 at 14:23
3

To future users who are going over this page, here is a step-by-step guide to installing lxml on Mac OSX.

  1. Go to Xcode, and go to Preferences, and then go to the Downloads tab, and select "Command Line Tools". Download Command Line Tools

  2. Go to Applications, then Utilities, and then Terminal, and open the Terminal. In terminal, type "easy_install pip". Note: If it says "error: /usr/local/bin/pip: Permission denied", then type "chmod 777 /usr/local/bin/". now try step 2 again.

  3. Type: pip install "Cython>=0.18"

  4. After it is finished, type: pip install lxml

  5. Open up python IDLE and test if you can import lxml, have fun!

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
  • This is not sufficient; trying it outputs: /lxml/src/lxml/includes/etree_defs.h:9:10: fatal error: 'libxml/xmlversion.h' file not found – Petri Nov 04 '13 at 20:34
  • 1
    In my case I was simply able to use `pip install lxml` in part because I already had Xcode and a reasonably new version of Cython installed. – Jim Dennis Jan 08 '17 at 05:36
1

I had to do: "sudo port uninstall py-lxml", "sudo port uninstall py24-lxml", and "sudo port install py27-lxml" and then I uninstalled lxml with pip, and re-installed with pip and it worked!

janex
  • 497
  • 4
  • 14
  • 1
    Thanks! Your uninstall tip helped me solve my similar question at http://stackoverflow.com/questions/22752332/cannot-install-lxml-3-3-3-on-osx-10-9-with-buildout – Brad M Mar 31 '14 at 09:45