ModuleNotFoundError:没有名为“Versioner”的模块

2024-04-20 10:12:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用下面的dockerfile构建一个图像

FROM <custom registry>/python:alpine3.7
# Copy local code to the container image.
ENV APP_HOME app
WORKDIR $APP_HOME
COPY . .
#RUN pip install versioneer
RUN pip install Flask google-auth google-cloud-storage numpy datetime pandas sklearn
ENV PORT 8080
CMD ["python", "app_hello.py"]

当我尝试进行docker构建时,它给了我以下错误

File "setup.py", line 37, in <module>
      import versioneer
  ModuleNotFoundError: No module named 'versioneer'
  
  ----------------------------------------
Command "/usr/local/bin/python /usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmp8gvrvde_" failed with error code 1 in /tmp/pip-install-s551_g8p/numpy

我也尝试安装Versioner,但没有成功。 我错过了什么


Tags: installpipruninpynumpyenvapp
1条回答
网友
1楼 · 发布于 2024-04-20 10:12:19

Command "/usr/local/bin/python /usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/in_process.py get_requires_for_build_wheel /tmp/tmp8gvrvde" failed with error code 1 in /tmp/pip-install-s551_g8p/numpy

生成numpy时会发生错误,这表示您需要升级pip以使其正常工作:

pip install  upgrade pip

此外,您还需要安装编译器,以便使用下一步进行生成:

apk add build-base

在上面的示例中,下面是一个可用的Dockerfile:

FROM python:alpine3.7
RUN pip install  upgrade pip; apk add build-base; pip install numpy
RUN python -c "import numpy; print(numpy.__version__)"

输出:

$ docker build -t abc:1 .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM python:alpine3.7
  -> 00be2573e9f7
Step 2/3 : RUN pip install  upgrade pip; apk add build-base; pip install numpy
  -> Running in bba4eed0d626
Collecting pip
  Downloading https://files.pythonhosted.org/packages/8a/d7/f505e91e2cdea53cfcf51f4ac478a8cd64fb0bc1042629cedde20d9a6a9b/pip-21.2.2-py3-none-any.whl (1.6MB)
Installing collected packages: pip
  Found existing installation: pip 19.0.1
    Uninstalling pip-19.0.1:
      Successfully uninstalled pip-19.0.1
Successfully installed pip-21.2.2
...
Collecting numpy
  Downloading numpy-1.21.1.zip (10.3 MB)
...
Successfully built numpy
Installing collected packages: numpy
Successfully installed numpy-1.21.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Removing intermediate container bba4eed0d626
  -> 6e11968fe036
Step 3/3 : RUN python -c "import numpy; print(numpy.__version__)"
  -> Running in 0f4c47db07cd
1.21.1
Removing intermediate container 0f4c47db07cd
  -> f189962ad246
Successfully built f189962ad246
Successfully tagged abc:1

相关问题 更多 >