python模块未正确安装,原因不明
我想为提供CLI工具的包创建Docker映像。 如果我从我们的pypi服务器安装包,我的映像就可以工作,但是如果我从源代码安装包,映像就不能工作。 需要从源代码安装,以使开发人员能够在发布新版本之前在容器中测试其代码python模块未正确安装,原因不明,python,pip,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 ba
# 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'
tmw_1 |回溯(最近一次呼叫最后一次):
tmw|U 1 |文件“/usr/local/bin/tagger model workbench”,第6行,在
tmw_1|来自tagger_model_workbench.app.main导入main
tmw| ModuleNotFoundError:没有名为“tagger_model_workbench”的模块
使用pip安装进行安装
正确地从我们的内部pypi安装包,而使用构建工件进行构建和安装则不正确。
构建命令是相同的。有人能解释一下发生了什么吗?似乎
tagger\u model\u workbench
是包含模块源代码的文件夹。如果按上述方式复制,则只会复制文件夹的内容,而不会复制文件夹。根据setup.py
的不同,如果您在setup.py
中引用packages
列表中的文件夹,而不是列出文件夹的内容,则可能导致模块没有任何python文件。如果模块中没有python文件,您将得到描述的错误消息
如果我认为tagger\u model\u workbench
是一个文件夹的假设是正确的,您可以简单地修复它。只需确保您正在将完整的文件夹添加到docker映像。只需按照以下方式调整复制setup.py
的行:
COPY setup.py MANIFEST.in /app/
COPY tagger_model_workbench /app/tagger_model_workbench
你知道我怎么能把这些都放在一行吗?我不想为我想在容器中的每个目录创建一个额外的
副本
。。确保只需创建一个包含所有要添加到docker映像的文件和文件夹的文件夹,并将此文件夹用于COPY命令。对于您的情况,例如,一个文件夹称之为app,并将您希望在docker映像中包含的所有文件和文件夹放在该文件夹中,然后您可以调用COPY app./app/