Many python packages have build dependencies on non-Python packages. I'm specifically thinking of lxml and cffi, but this dilemma applies to a lot of packages on PyPI. Both of these packages have unadvertised build dependencies on non-Python packages like libxml2-dev, libxslt-dev, zlib1g-dev, and libffi-dev. The websites for lxml and cffi declare some of these dependencies, but it appears that there is no way to do figure this out from a command line.
As a result, there are hundreds of questions on SO that take this general form:
pip install foo
fails with an error: "fatal error: bar.h: No such file or directory". How do I fix it?
Is this a misuse of pip
or is this how it is intended to work? Is there a sane way to know what build dependencies to install before running pip
? My current approach is:
foo
.pip install foo
foo
has a dependency on a Python package bar
. bar
build fails, then look at error message and guess/google what non-Python dependency I need to install.sudo apt-get install libbaz-dev
sudo pip install bar
bar
succeeds.sudo pip uninstall foo
Step #4 is particularly annoying. Apparently pip
(version 1.5.4) installs the requested package first, before any dependencies. So if any dependencies fail, you can't just ask pip
to install it again, because it thinks its already installed. There's also no option to install just the dependencies, so you must uninstall the package and then reinstall it.
Is there some more intelligent process for using pip
?
Pip relies on package authors to stipulate the dependencies for their code in order to successfully download and install the package plus all required dependencies from the Python Package Index (PyPI).
Pip Check Command – Check Python Dependencies After Installation. Because pip doesn't currently address dependency issues on installation, the pip check command option can be used to verify that dependencies have been installed properly in your project. For example: $ pip check No broken requirements found.
This is actually a comment about the answer suggesting using apt-get
but I don't have enough reputation points to leave one.
If you use virtualenv a lot, then installing the python-packages through apt-get
can become a pain, as you can get mysterious errors when the python packages installed system-wide and the python packages installed in your virtualenv try to interact with each other. One thing that I have found that does help is to use the build-dep
feature. To build the matplotlib dependencies, for example:
sudo apt-get build-dep python-matplotlib
And then activate your virtual environment and do pip install matplotlib
. It will still go through the build process but many of the dependencies will be taken care of for you.
This is sort what the cran repositories suggest when installing R packages in ubuntu.
For most popular packages, There is a workaround for recent ubuntu systems. For example, I want to install matplotlib
. When you order pip install matplotlib
, it usually fails because of a missing dependency.
You can use apt-get install python-matplotlib
instead. For python3, you can use apt-get install python3-matplotlib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With