即使在dockerfile /requirements.txt中添加了numpy,在docker容器中使用numpy运行python代码时,也出现“模块未找到错误”

德博拉

我正在从开发容器中运行一些非常基本的python代码

我想让它与numpy一起使用

在我尝试使其与numpy一起使用之前,evrything可以正常工作。

我在python代码中写了这一行:import numpy as np

这些是我在容器中安装numpy的步骤:

我在dockerfile中为numpy添加了pip install:(pip install numpy==1.14.3有和没有版本...)我收到此错误:

import numpy as np
ModuleNotFoundError: No module named 'numpy'

我尝试在requirements.txt和COPY requirements.txt /tmp/pip-tmp/dockerfile中添加numpy

这是我的Dockerfile:

FROM python:3

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Uncomment the following COPY line and the corresponding lines in the `RUN` command if you wish to
# include your requirements in the image itself. It is suggested that you only do this if your
# requirements rarely (if ever) change.
COPY requirements.txt /tmp/pip-tmp/

# Configure apt and install packages
RUN apt-get update \
    && pip install numpy==1.14.3 \
    && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
    #
    # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
    && apt-get -y install git openssh-client iproute2 procps lsb-release \
    #
    # Install pylint
    && apt-get -y install libc-dev \
    && apt-get -y install build-essential \
    && pip install -U pip \
    && pip --disable-pip-version-check --no-cache-dir install pylint \
    #&& pip install --no-cache-dir numpy scipy pandas matplotlib \
    #
    # Update Python environment based on requirements.txt
    && pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
    && rm -rf /tmp/pip-tmp \
    #
    # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
    && groupadd --gid $USER_GID $USERNAME \
    && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
    # [Optional] Add sudo support for the non-root user
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    #
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog

我有同样的错误

(我建立了容器,并在每个步骤之后重新运行它)

如果您知道如何帮助我修复它,请告诉我

1991

为确保您未使用其他python环境,请通过安装在容器中创建python虚拟环境python3-virtualenv并使用以下命令将其激活。

RUN python3 -m virtualenv --python=/usr/bin/python3 /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

如果问题仍然存在,请尝试手动删除容器映像并重新创建它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档