Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should python-dev be required to install pip

I find that many people have troubles installing python packages with pip because python-dev is not installed. Mainly, the error:

fatal error: Python.h: No such file or directory

So the question: Should python-dev be a required dependency of pip? Or is this only an issue for certain packages being installed with pip, and if so, are there certain steps to take to ensure users do not encounter the error when installing your modules?

like image 220
hansonap Avatar asked Jan 24 '14 19:01

hansonap


People also ask

Do I need Python to install pip?

PIP is automatically installed with Python 2.7.9+ and Python 3.4+ and it comes with the virtualenv and pyvenv virtual environments. Before you install PIP on Windows, check if PIP is already installed. 1.

Why do I need Python dev?

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.

What does pip install dev do?

The pip install <package> command always looks for the latest version of the package and installs it. It also searches for dependencies listed in the package metadata and installs them to ensure that the package has all the requirements that it needs.

Why is pip install not working in Python?

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you're trying to run in your current directory. In most cases, you'll need to navigate to the directory in which the tool is installed before you can run the command to launch it.


1 Answers

I don't think this actually belongs on StackOverflow, but in case I'm wrong…

First, python-dev is not a Python thing, it's an Ubuntu or Fedora or some other distro thing. If you download, build, and install Python, or run any binary installer from python.org, you get Python.h installed in an appropriate place. Many linux distros like to split packages into subpackages, moving stuff you only need for building into a -dev or similar package, and there's absolutely nothing wrong with doing that to Python, but it's still something the distro is doing.

Second, Python.h is not needed for building all packages, only those that include C extension modules. Since many packages are pure-Python and have no such extension modules, it makes sense that a distro's pip package wouldn't require its python-dev package. (In the same way that a distro's pip package probably wouldn't require a C compiler.)

Third, most distros that give you a python-pip or similar package also give you packages for popular packages. If you install them that way, either you won't need python-dev (and a C compiler), because they're binary packages, or you will need them but they'll be pulled in as a dependency (rpm, deb, etc. all have a way to specify separate "build" and "run" dependencies).

But if you go behind your package manager's back and try to install packages with pip (which is a reasonable thing to do), the package manager can't tell you which packages need what dependencies, while pip can only tell you about Python package dependencies, so there's nothing to enforce this.

like image 126
abarnert Avatar answered Oct 17 '22 22:10

abarnert