0
votes

I am setting a Docker service for bacnet using Debian10 and python2.7. When I install python by the command apt-get install -y python-pip my application works fine. Howerver when I try installing python2.7 by downloading and extracting, the docker service throws the next error:

  File "src/main.py", line 1, in <module>
    from bacpypes.core import run as runbacpypes
  File "/usr/local/lib/python2.7/site-packages/bacpypes/__init__.py", line 75, in <module>
    from . import local
  File "/usr/local/lib/python2.7/site-packages/bacpypes/local/__init__.py", line 7, in <module>
    from . import object
  File "/usr/local/lib/python2.7/site-packages/bacpypes/local/object.py", line 140, in <module>
    local_name_re = re.compile(u"^" + PN_LOCAL + u"$", re.UNICODE)
  File "/usr/local/lib/python2.7/re.py", line 194, in compile
    return _compile(pattern, flags)
  File "/usr/local/lib/python2.7/re.py", line 251, in _compile
    raise error, v # invalid expression
sre_constants.error: bad character range

Portion of the Dockerfile that causes the error:

  • Command apt-get install -y python-pip that works
FROM debian:10

RUN apt-get update && apt-get install -y python-pip
  • Download and extract python (causes the error)
FROM debian:10

RUN apt-get update \
  && apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \
  && apt-get clean
WORKDIR /tmp/

# Build python from source
ARG PYTHON_VERSION=2.7.18
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
  && tar --extract -f Python-$PYTHON_VERSION.tgz \
  && cd ./Python-$PYTHON_VERSION/ \
  && ./configure --with-ensurepip=install --prefix=/usr/local \
  && make && make install \
  && cd ../ \
  && rm -r ./Python-$PYTHON_VERSION*

Rest of the Dockerfile content (bacnet dependencies):

ARG PAHO_MQTT_VERSION=1.6.1
ADD bacnet/source-code-dependencies/paho_mqtt-$PAHO_MQTT_VERSION/ ./paho_mqtt-$PAHO_MQTT_VERSION/
RUN cd ./paho_mqtt-$PAHO_MQTT_VERSION/ \
  && python setup.py install \
  && cd ../ \
  && rm -r ./paho_mqtt-$PAHO_MQTT_VERSION*

# RUN pip install bacpypes==0.18.0
ARG BACPYPES_VERSION=0.18.0
ADD bacnet/source-code-dependencies/bacpypes-$BACPYPES_VERSION/ ./bacpypes-$BACPYPES_VERSION/
RUN cd ./bacpypes-$BACPYPES_VERSION/ \
  && pip install bacpypes-0.18.0-py2-none-any.whl \
  && cd ../ \
  && rm -r ./bacpypes*

WORKDIR /bacnet
ADD bacnet/site-packages ./site-packages
ADD bacnet/src ./src

WORKDIR /bacnet
ENV PYTHONPATH=/bacnet/src/Bacnet
CMD ["python", "src/main.py"]

What the reason for this error when building python from source code could be? I've tried different versions of python 2.7 and it always happens.

I have read in different threads the reason for the sre_constants.error: bad character range is caused by placing a hyphen after a \s character but no idea why just the way installing the same python version makes it happen or not.