The Error:
RuntimeError: Broken toolchain: cannot link a simple C program
Means it either can't find your C compiler or encountered problems linking a simple C program.
Demo docker walkthrough, to get Python2/pip to puke that error:
Keeping this demo confined inside a read-only docker image helps us be fearless in issuing OS-wrecking root level commands and start fresh every time:
#download a read only docker image that doesn't have gcc installed:
docker pull frolvlad/alpine-python2
#check the version of pip and python:
docker run --rm frolvlad/alpine-python2 pip --version
#pip 20.3.4 from /usr/lib/python2.7/site-packages/pip (python
Try to pip install numpy, you can't because pip needs gcc:
docker run --rm frolvlad/alpine-python2 pip install --user numpy
#...
#RuntimeError: Broken toolchain: cannot link a simple C program
gcc clearly not installed:
docker run --rm frolvlad/alpine-python2 which gcc
#empty output, gcc is not installed
So install it, now the binary /usr/bin/gcc exists:
docker run --rm frolvlad/alpine-python2 sh -c "apk update && apk add make automake gcc g++ subversion python2-dev && which gcc"
#/usr/bin/gcc
Apologies for stacking terminal commands but this is a read only image so everything has to be redone every time:
Now pip can use gcc and install numpy for python2:
docker run --rm frolvlad/alpine-python2 sh -c "apk update && apk add make automake gcc g++ subversion python2-dev && pip install numpy && python -c 'import numpy as np; print(np.__name__, np.__version__)'"
# ...
#Successfully installed numpy-1.16.6
#('numpy', '1.16.6')
We're in a good place so freeze the docker image and rename it.
docker images
#choose the most recent container id: 751420a548c1:latest and rename it:
docker commit 751420a548c1:latest frolvlad/alpine-python2_numpy
Now you have a new read only docker image with python2, pip and updated 1.16.6 numpy, ready to run your legacy python2 software like it's 2005:
docker run --rm frolvlad/alpine-python2_numpy python -c 'import numpy as np; print(np.__name__, np.__version__)'
#('numpy', '1.16.6')
Or to make the above commands simpler and sequential:
Use the -it
flag on docker run
which means open an interactive terminal from the docker image:
$ docker run -it frolvlad/alpine-python2_numpy sh
/ > python2 -c 'import numpy as np; print(np.__version__)'
1.16.6
/ > which gcc
/usr/bin/gcc
/ > python2 -c 'import numpy as np; print(np.zeros(3))'
[0. 0. 0.]
/ > echo "headward free now to rise"; exit;
As python2 packages fall further into ancient history, pip will have to be configured to point at your a private python2 package repository url.