python模块没有明显的原因未正确安装

时间:2019-07-30 19:54:13

标签: python pip

我想为提供CLI工具的软件包创建Docker映像。 如果从pypi服务器安装软件包,则我的映像有效,但如果从源代码安装,则映像不起作用。 必须进行从源安装,以使开发人员能够在发布新版本之前测试其容器中的代码。

# Building is done using
# docker build . --build-arg PIPCONTENT="`cat ~/.pip/pip.conf | base64 `" -t tmw:latest
#
FROM python:3.6-slim as base

RUN mkdir /app
WORKDIR /app

# this is our first build stage, it will not persist in the final image
FROM base as intermediate

RUN apt-get update && apt-get install -y \
    build-essential \
 && rm -rf /var/lib/apt/lists/*

## contains credentials
ARG PIPCONTENT
RUN mkdir -p /root/.pip/ && echo ${PIPCONTENT}  | base64 -d > /root/.pip/pip.conf

COPY requirements.txt /app/
RUN pip install -r requirements.txt

COPY setup.py MANIFEST.in tagger_model_workbench /app/

# doesn't create /usr/local/lib/python3.6/site-packages/tagger_model_workbench
#RUN python setup.py sdist
#RUN pip install dist/*.tar.gz

# TeamCity: python setup.py sdist && twine upload --verbose -r pypicloud dist/*
# does create /usr/local/lib/python3.6/site-packages/tagger_model_workbench
RUN pip install tagger-model-workbench

# build final image
#FROM base

#COPY --from=intermediate /usr/local /usr/local

EXPOSE 8050
ENTRYPOINT ["tagger-model-workbench", "0.0.0.0", "8050"]

这是setup.py:

import os

from setuptools import setup, find_packages


def get_install_requires():
    with open(os.path.join(os.path.dirname(__file__), "requirements.txt")) as f:
        return [line for line in map(str.strip, f) if line and not line.startswith('-') and not line.startswith("git+")]


setup(
    name='tagger_model_workbench',
    version='0.2.4',
    packages=find_packages(include=("tagger_model_workbench", "tagger_model_workbench.*",)),
    url='',
    license='',
    author='',
    author_email='',
    description='',
    install_requires=get_install_requires(),
    entry_points={
        'console_scripts': ['tagger-model-workbench=tagger_model_workbench.app.main:main'],
    }
)

使用python setup.py sdist && pip install dist/*.tar.gz选项运行容器会导致以下错误消息:

tmw_1  | Traceback (most recent call last):
tmw_1  |   File "/usr/local/bin/tagger-model-workbench", line 6, in <module>
tmw_1  |     from tagger_model_workbench.app.main import main
tmw_1  | ModuleNotFoundError: No module named 'tagger_model_workbench'

使用pip install进行安装可以从内部pypi正确安装软件包,而不能使用内置工件进行安装。 生成命令是相同的。谁能解释发生了什么事?

1 个答案:

答案 0 :(得分:1)

似乎tagger_model_workbench是包含模块源代码的文件夹。如果以上述方式复制它,则只会复制文件夹的内容,而不会复制文件夹。如果您引用setup.py的{​​{1}}列表中的文件夹而不是列出文件夹的内容,则可能会导致模块没有任何python文件,这取决于您的packages。如果模块中没有python文件,您将收到描述的错误消息。

如果我认为setup.py是文件夹是正确的,则可以简单地对其进行修复。只要确保将完整的文件夹添加到Docker映像即可。只需按照以下方式修改复制tagger_model_workbench的行:

setup.py
相关问题