简体   繁体   English

使用 pyenv 安装 python 时出现“无模块 dbm”

[英]"No module dbm" when using pyenv installed python

I'm looking to use pyenv to manage multiple python versions within a docker image.我希望使用 pyenv 来管理 docker 映像中的多个 python 版本。 I'm currently having an issue when running python2.7.17 in a debian:buster-slim image where it is missing a package dbm :我目前在debian:buster-slim图像中运行python2.7.17时遇到问题,其中缺少 package dbm

Python 2.7.17 (default, Apr 22 2021, 18:07:32)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named dbm

What's interesting the system version of python loads this module just fine:有趣的是 python 的系统版本加载这个模块就好了:

Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbm
>>> print(dbm)
<module 'dbm' from '/usr/lib/python2.7/lib-dynload/dbm.x86_64-linux-gnu.so'>

Pyenv Python3 install does not have this issue. Pyenv Python3 安装没有这个问题。 This is only occurring with Python2.7.这仅在 Python2.7 中发生。

I found this post which is some what related but had no luck with the solution: GDBM doesn't work with Python 3.6 and anaconda我发现这篇文章有些相关但对解决方案没有运气: GDBM doesn't work with Python 3.6 and anaconda

Any ideas why I'm missing dbm.so when using pyenv but not when using my system version python?任何想法为什么我在使用 pyenv 时缺少dbm.so而在使用我的系统版本 python 时却没有?

I fixed this by placing the pyenv install commands at the top of the Dockerfile before any other custom build logic:我通过在任何其他自定义构建逻辑之前将 pyenv install 命令放在 Dockerfile 的顶部来解决此问题:

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    ca-certificates \
    build-essential \
    git \
    unzip \
    bzip2 \
    libsqlite3-dev \
    libssl-dev \
    libbz2-dev \
    libffi-dev \
    libdb-dev \
    python-gdbm \
    libreadline-dev \
    python-openssl \
    zlib1g-dev \
    build-essential \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
ENV PREV_USER="$USER"
ENV PYENV_ROOT=/home/myuser/.pyenv
ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"
USER myuser
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl https://pyenv.run | bash \
    && eval "$(pyenv init -)" \
    && eval "$(pyenv virtualenv-init -)" \
    && pyenv install 2.7.17 \
    && pyenv install 3.6.10
USER $PREV_USER

Not sure about the specifics but it works now.不确定具体细节,但现在可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM