python icon

How to install Python modules

Today I have found some strange behavior with Python modules installation. The whole story began when I was asked to install docker module of python and to write some script.

As you know the easiest way to install any Python module is by using pip. So I used:

Which installed latest version of docker module which was 2.0.1. with all necessary dependencies.

But … then I started python from command line and tried to import the docker module I got error, like this:

The python couldn’t find one of dependencies modules called backports.ssl-match-hostname. But pip is showing that the package ssl_match_hostname is installed, however somehow called backports.ssl-match-hostname:

If you try to get information about the module backports.ssl-match-hostname, you’ll see:

The module is installed in /usr/local/lib/python2.7/dist-packages.

After I searched the google by the error message. I got something about “shadowing the package”, but no solution for the problem.

The solution is to not use PIP at all! If you need some Python module just get it from APT. Search for python-<module name>:

Uninstall via pip all modules that have been installed with docker module:

And then install python-docker deb package via apt:

It will install dependencies. After that import works well, no errors.

The only difference is now the module installed in another folder:

So if you are using Ubuntu, or Elementary OS as me,  don’t use pip. Install python modules through apt as all regular packages.

About pavel

One thought on “How to install Python modules”