0

I have a Dockerfile that I am attempting to build which inherits from an image that uses Python 2.7. I upgraded the python to 3 and installed pip3 as well and tried to install the rest of my desired packages but I keep getting a syntax error (likely because it is using Python 2.7 and the pip3 uses Python3 syntax).

Here is the error I am getting:

Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip._internal.cli.main import main
  File "/usr/local/lib/python3.4/dist-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

And here is the Dockerfile I am using to build.

FROM geodata/gdal

ENV DEBIAN_FRONTEND noninteractive

LABEL maintainer="Joe Doe"
LABEL description="Docker for GDAL"
RUN sudo apt-get update && \
    sudo apt-get install -y git && \
    sudo apt-get install -y python3 python3-setuptools && \
    sudo apt-get install -y python3-pip && \
    sudo apt-get install -y wget && \
    sudo apt-get clean

RUN sudo rm /usr/bin/python && \
    sudo ln -s /usr/bin/python3 /usr/bin/python

RUN python3 -m pip install --upgrade pip
RUN pip3 install pandas geopandas shapely fiona

CMD ["/bin/bash"]

I thought adding

RUN sudo rm /usr/bin/python && \
    sudo ln -s /usr/bin/python3 /usr/bin/python

would help by setting python3 to the python command, but this doesn't help either.

Steve Ahlswede
  • 547
  • 1
  • 4
  • 14
  • Does the `python3` line work alright? Maybe change the next line from pip3 to python, i.e. `python3 -m pip install pandas geopandas shapely fiona`. Not sure about the error. – Steve Apr 15 '21 at 10:24
  • Python 3 → `pip3`; Python 2 → EOL (Try to avoid images using Python 2!) – Klaus D. Apr 15 '21 at 10:31

0 Answers0