3

I have Centos 6 on my server and I've been trying to install a few packages (modules) for it. I just brought the ones on my windows to the 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 perfectly on Windows 7 & Linux Ubuntu 10.04.

Does anyone know why it returns this error? I haven't modified 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

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
RewriteRule
  • 41
  • 1
  • 6

2 Answers2

6

Or install it from EPEL (the 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
Michel Samia
  • 4,273
  • 2
  • 24
  • 24
1

lxml is not a pure Python module. It's mostly written in Cython and hence compiles to native code. The binary files from your Windows machine are incompatible with CentOS (and Linux in general).

Your best bet is to follow the instructions on installing lxml, i.e., install the libxslt-devel and libxml2-devel packages and use pip to compile lxml or compile it manually yourself. If you go for compiling it yourself, there's a previous question with some useful info and further info on the lxml site.


Installation

I don't have a CentOS machine to test this on. The easiest method to install would be via ip, which should be available as a package through Yum. If not, you can install it using the following commands (from the documentation for distribute, a pre-requisite 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 install fine.

If you want to skip pip (though, ultimately, pip makes managing dependencies a lot easier, so its well worth doing)

  1. Locate the appropriate version of lxml on PyPI
  2. Download the source from the download URL (should be a tar.gz file)
  3. Extract the tar archive using tar -xzf lxml-<version>.tar.gz
  4. cd into the extracted directory and run python setup.py install

Note that any of the above commands may need to be run as root if your installation is only modifiable by root. Installation commands are python distribute_setup.py, easy_install pip and python setup.py install.

Community
  • 1
  • 1
ig0774
  • 39,669
  • 3
  • 55
  • 57
  • "Package libxml2-devel-2.7.6-8.el6_3.4.i686 already installed and latest version" + "Package libxslt-devel-1.1.26-2.el6_3.1.i686 already installed and latest version" ok so all I have to do now is to compile it using pip or myself? Could you please tell me how to compile it myself, never had to deal with such stuff as that.. – RewriteRule Jan 25 '13 at 13:22
  • thanks for the info, I did it with pip since it looks a bit more simple, but I still get some errors. I edited my first post because it makes my comment too long. I guess the installation is almost done, I did everything how it should be. – RewriteRule Jan 25 '13 at 13:42