Python lxml etree on CentOS 6.3

I have Centos 6 on my server and I am trying to install multiple packages (modules) for it. I just brought them to my windows to ftp client in /usr/lib/python2.6/site-packages

, but when I run my script one of them - lxml gives me an error:

File "plugins/util/http.py", line 12, in <module>
    from lxml import etree, html
  File "/usr/lib/python2.6/site-packages/lxml/html/__init__.py", line 12, in <module>
ImportError: cannot import name etree

      

The same code worked fine on Windows 7 and Linux Ubuntu 10.04.

Does anyone know why it is returning this error? I didn't change anything, just moved the module from windows to my python2.6 directory on my vps.

@root:

>>> import lxml;print lxml
<module 'lxml' from '/usr/lib/python2.6/site-packages/lxml/__init__.pyc'>
>>>

      

@ig

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp, -D_FORTIFY_SOURCE = 2 -fexceptions -fstack-protector -param = ssp-buffer-size = 4 -m32 -march = i686 -mtune = atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp, -D_FORTIFY_SOURCE = 2 -fexceptions -fstack-protector -param = ssp-buffer-size = 4 -m32 -march = i686 -mtune = atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I / usr / include / libxml2 -I / tmp / pip-build / lxml / src / lxml / includes -I / usr / include / python2.6 -c src / lxml / lxml.etree.c -o build / temp.linux-i686-2.6 / src / lxml / lxml.etree.o

unable to execute gcc: no such file or directory

Error: command 'gcc' failed with exit status 1

+3


source to share


2 answers


Or install it from EPEL (easiest way):



# install EPEL if you don't have it yet
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# instal python-lxml
sudo yum -y install python-lxml

      

+6


source


lxml

is not a pure Python module. It is mostly written in Cython and therefore compiles to native code. The binaries from your Windows machine are not compatible with CentOS (and Linux in general).

Your best bet is to follow the installationlxml

instructions , i.e. install the packages libxslt-devel

and libxml2-devel

and use pip

to compile lxml

or compile it manually yourself. If you go to compile, there is a previous question with some useful information and more information on the site lxml

.


Installation

I don't have a CentOS machine to test this. The easiest way to install is via ip, which should be available as a package via Yum. If not, you can install it using the following commands (from the documentation for distribute , prerequisites for pip):

curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip

      



From there, just run:

pip install lxml

      

And it should fit perfectly.

If you want to skip pip (although pip ultimately makes dependency management easier, so it's worth doing)

  • Find the corresponding lxml version on PyPI
  • Download the source code from the download url (must be a file tar.gz

    )
  • Extract the tar archive using tar -xzf lxml-<version>.tar.gz

  • cd

    to the extracted directory and run python setup.py install

Note that any of the above commands may need to be run as administrator if your installation is only modified by root. Installation commands python distribute_setup.py

, easy_install pip

and python setup.py install

.

+1


source







All Articles