Created
February 12, 2021 09:58
-
-
Save peterroelants/23cd89ca4f8585e3a9d1cdf3d477c879 to your computer and use it in GitHub Desktop.
Reduce python container size by compiling with pip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Install python packages with pip using compilation to reduce size | |
| # - https://towardsdatascience.com/how-to-shrink-numpy-scipy-pandas-and-matplotlib-for-your-data-product-4ec8d7e86ee4 | |
| # - https://avilpage.com/2020/02/reduce-python-package-footprint.html | |
| # - https://stackoverflow.com/a/22942120 | |
| # - https://blog.mapbox.com/aws-lambda-python-magic-e0f6a407ffc6 | |
| # `/usr/local/bin/python3-config --cflags` should be applied automatically, the | |
| # following flags extend these. | |
| RUN pip install --upgrade pip \ | |
| && export CFLAGS="${CFLAGS} -g0 -Wl,--strip-all -Os -I/usr/include:/usr/local/include" \ | |
| && export LDFLAGS="${LDFLAGS} -L/usr/lib:/usr/local/lib" \ | |
| && pip install \ | |
| --no-cache-dir \ | |
| --trusted-host pypi.python.org \ | |
| --compile \ | |
| --global-option=build_ext \ | |
| --global-option="-j 8" \ | |
| --requirement /tmp/requirements.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment