What is python-dev package used for
Asked Answered
M

3

100

I recently installed lxml.

Before that, I had to install all the dependencies for that. So I tried to install liblxml2-dev, liblxslt1-dev and python-dev (google-searched for what packages are required for lxml) but even after that, I could not able to install lxml by using the command pip install lxml.

However as because I am using Python 3.4.0, I thought that may be there are different version of python-dev (thought came due to facing some similar version conflict problem). So I tried to install python3-dev.

Then I tried to install lxml using the same command said earlier and that worked!!!

I google-searched for those sentences and I could able to understand the meaning of lxml and xslt. I found a link for python-dev but I am not still sure what it is actually doing.

OS - Ubuntu

Meitner answered 23/6, 2015 at 11:54 Comment(1)
Different platforms have different conventions; the question should mention which OS you are on (I'm guessing Debian Linux or a derivative like Ubuntu or Mint, though RPM-based distros have a similar arrangement with a separate -dev package for headers).Despondency
O
110

python-dev

python-dev contains the header files you need to build Python extensions.

lxml

lxml is a Python C-API extension that is compiled when you do pip install lxml. The lxml sources have at least something like #include <Python.h> in the code. The compiler looks for the header file Python.h during compilation, hence those header files need to be on your system such that they can be found.

-dev packages on Linux

On Linux typically, the binary libraries and header files of packages like Python are separate. Hence you can have Python (e.g. package python) installed and everything works fine. But when you want to build extensions you need to install the corresponding -dev package.

Optime answered 23/6, 2015 at 11:58 Comment(3)
You said when you want to build extensions you need to install the corresponding dev package. Can you please explain more on it?. How header files are building extensionsMeitner
The header files are needed when you build the extension. The extension source code references header files of the libraries it uses. When the Python extension is built it uses the Python shared library that contains the Python API C functions and data structures. This applies not only to Python but to almost all libraries and applications you install on your system. Whenever you write a program that uses the librarie's API you need the corresponding devel package to build your program.Optime
Yes, on Windows this is similar. Typically libraries provide SDK packages (zip or installers) which include the header files. When you build extensions for Python they often are compiled with the Visual Studio tools and the VS project files need to reference these header files.Optime
B
21

python-dev is the package that contains the header files for the Python C API, which is used by lxml because it includes Python C extensions for high performance.

Benuecongo answered 23/6, 2015 at 11:59 Comment(0)
B
7

python-dev contains everything needed to compile python extension modules (https://docs.python.org/2/extending/extending.html).

Note that Debian already has an lxml package for python 3 (mentioned at http://lxml.de/installation.html); in general it's a good idea to use the packaged version. I'd suggest pip uninstall lxml and then apt-get install python3-lxml.

Beano answered 23/6, 2015 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.