Installing numpy on Docker Alpine

前端 未结 6 1796
误落风尘
误落风尘 2020-12-08 19:26

I\'m trying to install numpy in a docker container based on Alpine 3.1. I\'m using the following Dockerfile:

FROM alpine:3.1
RUN apk add --update make cmake          


        
6条回答
  •  感动是毒
    2020-12-08 19:49

    A package is now available in the Alpine repository: py3-numpy. But you won't be able to use it straightaway.

    py3-numpy installs libraries into /usr/lib/python3.8/site-packages directory but the default Python module path does not use it:

    $ docker run -it python:3.8-alpine sh
    / # apk add --update --no-cache py3-numpy
    / # python
    >>> import numpy
    Traceback (most recent call last):
      File "", line 1, in 
    ModuleNotFoundError: No module named 'numpy'
    >>> import sys
    >>> sys.path
    ['', '/usr/local/lib/python38.zip', '/usr/local/lib/python3.8', '/usr/local/lib/python3.8/lib-dynload', '/usr/local/lib/python3.8/site-packages']
    

    This can be fixed by setting the $PYTHONPATH environment variable to the path of the site-packages in /usr/lib:

    FROM python:3.8-alpine
    
    RUN apk add --update --no-cache py3-numpy
    ENV PYTHONPATH=/usr/lib/python3.8/site-packages
    

提交回复
热议问题