¿Cómo instalar lxml en OS X Leopard sin usar MacPorts o Fink?


He intentado esto y me he topado con problemas un montón de veces en el pasado. ¿Alguien tiene una receta para instalar lxml en OS X sin MacPorts o Fink que definitivamente funcione?

Preferiblemente con pasos completos de 1-2-3 para descargar y construir cada una de las dependencias.

Author: syntagma, 2009-08-14

16 answers

Gracias a @jessenoller en Twitter tengo una respuesta que se ajusta a mis necesidades: puede compilar lxml con dependencias estáticas, evitando así jugar con libxml2 que viene con OS X. Esto es lo que funcionó para mí:

cd /tmp
curl -O http://lxml.de/files/lxml-3.6.0.tgz
tar -xzvf lxml-3.6.0.tgz 
cd lxml-3.6.0
python setup.py build --static-deps --libxml2-version=2.7.3  --libxslt-version=1.1.24 
sudo python setup.py install
 35
Author: Simon Willison,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-03 19:42:09

Esto funcionó para mí (10.6.8):

sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml
 32
Author: Andrei,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-07-26 08:44:03

He tenido una excelente suerte con Homebrew para instalar la dependencia libxml2:

brew install libxml2

Homebrew no parece tener libxslt disponible, pero todavía no he tenido la necesidad de XSLT. YMMV.

Una vez que tenga la(s) dependencia (s), entonces los métodos habituales funcionan bien:

pip install lxml

O

easy_install lxml
 20
Author: David Eyk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-04-26 01:32:08

Easy_install puede trabajar usando esto:

STATIC_DEPS = true easy_install 'lxml> = 2. 2beta4'

Es posible que luego necesite ejecutarse, dependiendo de los permisos;

STATIC_DEPS = true sudo easy_install 'lxml> = 2. 2beta4'

Véase http://muffinresearch.co.uk/archives/2009/03/05/install-lxml-on-osx /

 5
Author: ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-26 10:05:27

Usando homebrew (0.9.5) en el capitán (10.11.1) lo siguiente funcionó para mí:

brew install libxml2
LD_FLAGS=-L/usr/local/opt/libxml2/lib CPPFLAGS=-I/usr/local/opt/libxml2/include/libxml2 pip install lxml
 5
Author: mizerlou,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-13 21:36:49

Esto funcionó para mí en 10.8.5

  1. Instalar Xcode desde Mac App Store
  2. Xcode -> Preferencias -> Descargas - > Herramientas de línea de comandos
  3. Instalar homebrew usando
  4. ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
  5. brew install libxml2
  6. sudo easy_install lxml

Esto incluye sugerencias de:

Pero quería compilarlo en una respuesta en lugar de dejar comentarios en todas partes

 3
Author: William Entriken,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 10:30:50

En OS X 10.9.1 la respuesta sugerida anteriormente errores durante la instalación had los siguientes cambios tuvieron que hacerse:

cd /tmp  
curl -o lxml-3.3.0.tgz http://lxml.de/files/lxml-3.3.0.tgz  
tar -xzvf lxml-3.3.0.tgz  
cd lxml-3.3.0  
python setup.py build --static-deps --libxml2-version=2.8.0  --libxslt-version=1.1.24  
sudo python setup.py install  
 3
Author: user785278,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-01 17:54:12

Esto me funcionó en el pasado instalar lxml en osx

 1
Author: muffinresearch,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-14 11:41:46

Esto funcionaba bien con Snow Lepoard, pero después de actualizar a Lion tuve que vincular gcc-4.2 a gcc. Ejecutando sudo env ARCHFLAGS= "- arch i386-arch x86_64 " easy_install lxml estaba buscando gcc-4.2 en lugar de gcc.

 1
Author: chuckles,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-10-21 14:06:12

Estoy usando OSX 10.11 El Capitan y Homebrew. Usar pip install lxml me daría "error fatal: 'libxml/xmlversion.h 'archivo no encontrado" y "falló con el código de error 1" bla bla.

De acuerdo con el sitio web oficial , debería usar STATIC_DEPS=true pip install lxml (agregue sudo antes de pip si lo necesita), y eso resolvió mi problema.

Ejecuté brew install libxml2 y brew install libxslt para instalar las dependencias durante la resolución de problemas. No estoy seguro de si esos dos comandos son necesarios.

 1
Author: feilong,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-17 01:31:09

Intente instalar Cython e instalar desde el código fuente, easy_install falla. Aún no me he probado mi mac.

Si no es así, la versión de ports no es tan antigua. Puedes ver las dependencias, algunas de las cuales tuvieron que ser actualizadas para mi compilación de Linux de lxml.

Info py25-lxml py25-lxml @2.1.5 (python, devel)

Lxml es un enlace pitónico para las bibliotecas libxml2 y libxslt. Es único en que combina la velocidad y la integridad de las características de estas bibliotecas con la simplicidad de una API nativa de Python, en su mayoría compatible pero superior a la bien conocido ElementTree API. Página principal: http://codespeak.net/lxml /

Dependencias de la biblioteca: python25, libxml2, libxslt, py25-hashlib, py25-setuptools, py25-zlib Plataformas: darwin Mantenedores: [email protected] [email protected]

 0
Author: Nick Martin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-14 11:15:46
 0
Author: Ross,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-14 11:15:50

Lxml está incluido en el repositorio pypm:

$ pypm install lxml
 0
Author: Sridhar Ratnakumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-21 18:02:00

Para instalar con versiones actualizadas de libxml2 y libxslt:

ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true pip install lxml

Para instalar con versiones específicas de bibliotecas:

ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSION=1.1.24 pip install lxml

CentOS 64 bit (un poco fuera de la pregunta, pero difícil ganado):

CFLAGS=-fPIC STATIC_DEPS=true pip install lxml

O

CFLAGS=-fPIC STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSION=1.1.24 pip install lxml
 0
Author: m.kocikowski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-04-25 21:21:11

Un montón de dolor entró en esto para un os x 10.6.8 desactualizado, pero aquí va para cualquier persona corriendo Snow Leopard!

Primero tienes que instalar una versión diferente de libxml2 desde homebrew e instalar install with-python. Puede hacer esto escribiendo los siguientes comandos.

brew update
brew edit libxml2

Luego encuentre la línea que dice "without without-python" y cambie a "with with-python".

system "./configure", "--disable-dependency-tracking",
                      "--prefix=#{prefix}",
                      "--with-python"

Ahora puede instalar libxml2.

brew install libxml2

A continuación, compruebe su nueva instalación de libxml2 en el ubicación predeterminada de homebrew. Desea encontrar la configuración de libxml2.

EL TUYO PUEDE SER DIFERENTE:

"/usr / local / Cellar / libxml2 / VERSION_ /bin/xml2-config "

Ahora use el siguiente comando para instalar lxml con pip utilizando la configuración de libxml2 recién instalada y no la versión de Mac OS X.

ARCHFLAGS="-arch i386 -arch x86_64" pip install lxml --install-option="--with-xml2-config=/usr/local/Cellar/libxml2/2.9.1/bin/xml2-config"

Funcionó para mí en mi 10.6.8 Python 2.6. Gracias.

El crédito va a esta página por mostrarme pip install install-option ...

http://natanyellin.com/page/4/

 0
Author: ganicus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-03 00:55:04

Lo compilo en /usr/local sin ningún problema.

Instale Python, libxml2, libxslt y luego lxml. Es posible que también necesite setuptools instalado.

 -5
Author: ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-14 10:33:46