Installing easy_install... to get to installing lxml

17,058

Solution 1

First off we don't use easy_install anymore. We use pip. Please use pip instead.

To get to your particular troubles, as the comments point out, you're missing GCC. On OS X, Xcode Command Line Tools provides GCC, as well as many other programs necessary for building software on OS X. For OS X 10.9 (Mavericks) and newer, either install Xcode through the App Store, or alternatively, install only the Xcode Command Line Tools with

xcode-select --install

For more details, please see the Apple Developer FAQ or search the web for "install Xcode Command Line Tools".

For older versions of OS X, you can get Xcode Command Line Tools from the downloads page of the Apple Developer website (free registration required).

Once you have GCC installed, you may still encounter errors during compilation if the C/C++ library dependencies are not installed on your system. On OS X, the Homebrew project is the easiest way to install and manage such dependencies. Follow the instructions on the Homebrew website to install Homebrew on your system, then issue

brew update
brew install libxml2 libxslt

Possibly causing further trouble in your case, you placed the downloaded setuptools in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/. Please do not download any files to this location. Instead, I suggest you download the file to your home directory, or your usual Downloads directory. After downloading it, you're supposed to run sh setuptools-X.Y.Z.egg, which will then install it properly into the appropriate site-packages and put the executable easy_install on your path.

Solution 2

Ensure you have libxml2-dev and libxslt1-dev installed

apt-get install libxml2-dev
apt-get install libxslt1-dev

Then your installation should build properly.

Solution 3

try: sudo apt-get install python-lxml

Solution 4

Make sure that all the following packages are installed on your system first:

gcc gcc-c++ python-devel libxml2 libxml2-dev libxslt libxslt-dev

You should be able to install them using some variant of: sudo apt-get install sudo yum install

Only after all of the above have been successfully installed should you attempt to run:

sudo pip install lxml

Solution 5

It looks like lxml wants to build an extension that requires access to a C compiler. You will need gcc for that. Try running sudo apt-get install build-essential and that should fix this particular issue.

Share:
17,058

Related videos on Youtube

Alex
Author by

Alex

Updated on February 05, 2020

Comments

  • Alex
    Alex over 4 years

    I've come to grips with the fact that ElementTree isn't going to do what I want it to do. I've checked out the documentation for lxml, and it appears that it will serve my purposes. To get lxml, I need to get easy_install. So I downloaded it from here, and put it in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/. Then I went to that folder, and ran sh setuptools-0.6c11-py2.6.egg.

    That installed successfully. Then I got excited because I thought the whole point of easy_install was that I could then just install via easy_install lxml, and lxml would magically get downloaded, built, and installed properly, ready for my importing enjoyment. So I ran easy_install lxml. I pasted the results below. What should I do?

    easy_install lxml
    Searching for lxml
    Reading http://pypi.python.org/simple/lxml/
    Reading http://codespeak.net/lxml
    Best match: lxml 2.2.6
    Downloading http://codespeak.net/lxml/lxml-2.2.6.tgz
    Processing lxml-2.2.6.tgz
    Running lxml-2.2.6/setup.py -q bdist_egg --dist-dir /var/folders/49/49N0+g5QFKCm51AbzMtghE+++TI/-Tmp-/easy_install-rxbP6K/lxml-2.2.6/egg-dist-tmp-fjakR0
    Building lxml version 2.2.6.
    NOTE: Trying to build without Cython, pre-generated 'src/lxml/lxml.etree.c' needs to be available.
    Using build configuration of libxslt 1.1.12
    Building against libxml2/libxslt in the following directory: /usr/lib
    unable to execute gcc-4.0: No such file or directory
    error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1
    
    • John Feminella
      John Feminella over 14 years
      (re: your code editor troubles) Indent by four spaces to make a code block, or click the "01010" button in the editor while you have some things highlighted.
  • John Feminella
    John Feminella over 14 years
    What OS/distribution is this on?
  • gotgenes
    gotgenes over 14 years
    @John The better command for Debain/Ubuntu is sudo apt-get install build-essential because it includes tools like make and a few other friends that are usually used in concert with gcc/g++.
  • John Feminella
    John Feminella over 14 years
    Ah. OSX doesn't install the gcc compiler. Get Homebrew (github.com/mxcl/homebrew) or its less-intelligent cousin, ports, and then install gcc through them instead. Most of your pain is happening because there isn't an official, sensible packager on OS X. Sorry. =/
  • John Feminella
    John Feminella over 14 years
    @gotgenes » You are right. Thank you for the correction; I've updated accordingly.
  • Alex
    Alex over 14 years
    I tried to mkdir homebrew in /usr/local, but it permission denied me. Usually it just asks for my password.
  • cit
    cit over 14 years
    OSX 10.5 is bundled with 2.5.1....Perhaps there is a conflict between the two versions....Did you install your own copy of Python 2.6? Might be a PATH issue...
  • Alex
    Alex over 14 years
    Yes. I installed Python 2.6. I don't understand what that has to do with getting permission denied when trying to mkdir homebrew from /usr/local.
  • wheleph
    wheleph over 12 years
    For Python3 use "apt-get install python3-lxml"
  • Muhd
    Muhd over 12 years
    +1 for pointing out we should be using pip. I had no idea. It's nice when packages just work.
  • mlissner
    mlissner over 11 years
    Better to use pip. It will give you a more recent version than your package maintainer. Sooner or later you'll be glad you used it.
  • gotgenes
    gotgenes over 9 years
    @mickey Thanks! Fixed.