高山码头工人:安装熊猫/ numpy

问题描述 投票:4回答:2

我如下安装py3-pandas,

 FROM alpine:latest

 RUN echo "http://dl-8.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
 RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories


 RUN apk add --update \
   python3 \
   python3-dev \
   py3-numpy py3-pandas py3-scipy py3-numpy-dev

然后我尝试导入熊猫,它不可用

bash-5.0# python3
Python 3.7.5 (default, Oct 17 2019, 12:25:15)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>> import sys
>>> sys.path
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/lib/python3.7/site-packages', '/retention']
>>>

因此原来熊猫安装在不同的python目录中

bash-5.0# apk info -L py3-pandas
....
usr/lib/python3.8/site-packages/pandas/__pycache__/__init__.cpython-38.pyc


bash-5.0# ls /usr/bin/python*
/usr/bin/python             /usr/bin/python2.7          /usr/bin/python3-config     /usr/bin/python3.7-config   /usr/bin/python3.7m-config
/usr/bin/python2            /usr/bin/python3            /usr/bin/python3.7          /usr/bin/python3.7m

如何使py3-pandas使用系统中已安装的python版本?

python pandas docker alpine
2个回答
1
投票

您正在混合使用您的版本-您的Dockerfile使用的是latest,但其中包括“ edge”存储库。

要使用Python 3.7(无测试库),可以使用以下代码:

FROM alpine:latest

RUN echo "http://dl-8.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories

但是您冒着将来更改版本的风险。最好使用:

FROM alpine:3.10

RUN echo "http://dl-8.alpinelinux.org/alpine/v3.10/community" >> /etc/apk/repositories

如果您确实想要Python 3.8和“测试”存储库,则必须使用latest(同样有更改版本的风险:]]

FROM alpine:edge

RUN echo "http://dl-8.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories

0
投票

您需要在Dockerfile中设置PYTONPATH环境变量。

© www.soinside.com 2019 - 2024. All rights reserved.