我按如下所示安装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版本?
答案 0 :(得分: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
答案 1 :(得分:0)
您需要在Dockerfile中设置PYTONPATH环境变量。
扩展模块文件的默认搜索路径。格式是 与Shell的PATH相同:一个或多个目录路径名,以 os.pathsep(例如Unix上的冒号或Windows上的分号)。 不存在的目录将被静默忽略。
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
ENV PYTHONPATH /usr/lib/python3.8/site-packages