AlexW
AlexW

Reputation: 2589

Docker - Python dependencies for installing modules via pip

I am building a Django implementation with docker. I'm using the python container as base, but in my requirements file I have the below:-

boto==2.43.0
boto3==1.4.4
botocore==1.5.55
ciscoconfparse==1.2.47
Django==1.11.4
django-appconf==1.0.2
django-auth-ldap==1.2.10
django-dbtemplates==2.0
django-debug-toolbar==1.7
easy-thumbnails==2.3
easysnmp==0.2.4
ipaddress==1.0.18
Jinja2==2.9.5
mysqlclient-1.3.10
netmiko==1.2.8
O365==0.9.5
orionsdk==0.0.6
paramiko==2.1.2
python-dateutil==2.6.0
python-ldap==2.4.32
pytz==2016.10
pyOpenSSL==17.2.0
sqlparse==0.2.3
urllib3==1.21.1
joblib==0.11

some of these have dependencies that fail when using the python container on its own, for example...

   #include <net-snmp/net-snmp-config.h>
                                        ^
  compilation terminated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for easysnmp
...
...
   #include "lber.h"
                    ^
  compilation terminated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for pyldap
...
...
    In file included from Modules/LDAPObject.c:9:0:
    Modules/errors.h:8:18: fatal error: lber.h: No such file or directory
     #include "lber.h"
                      ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-aufmftap/pyldap/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-fjdz1te2-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-aufmftap/pyldap/

how do I install OS dependencies for python modules? within a container? what os does the python container run on for me to get the right dependencies?

Thanks

Upvotes: 4

Views: 15646

Answers (2)

C&#233;line Aussourd
C&#233;line Aussourd

Reputation: 10664

Assuming you are using the python:3.6 image which is currently the latest, you need to install some additional libraries.

Dockerfile example (the pip libraries are in the requirements.txt file):

FROM python:3.6

RUN apt-get update -y \
    && apt-get install -y python-dev libsasl2-dev libldap2-dev libssl-dev libsnmp-dev

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt

Related question: I can't install python-ldap

Upvotes: 6

ZongoBoyX
ZongoBoyX

Reputation: 121

I had to update the run command to get it to work

RUN apt-get update -y
RUN apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev libsnmp-dev -y

Upvotes: 0

Related Questions