警告:“news”是 pyproject.toml 中定义的入口点,但它没有作为脚本安装。你可能会得到不正确的 `sys.argv[0]`

Pir*_*App 7 python docker dockerfile python-packaging python-poetry

    \n
  • 我正在尝试使用 docker compose 在 docker 中运行我的基于诗歌的 python 项目
  • \n
  • 当我运行该应用程序时,它可以工作,但它给了我这个警告
  • \n
\n
ch_news_dev_python          | Warning: 'news' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`.\nch_news_dev_python          | \nch_news_dev_python          | The support to run uninstalled scripts will be removed in a future release.\nch_news_dev_python          | \nch_news_dev_python          | Run `poetry install` to resolve and get rid of this message.\n
Run Code Online (Sandbox Code Playgroud)\n

我的项目结构

\n
news\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 docker\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 development\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ...\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 python_server\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Dockerfile\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .env\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 docker-compose.yml\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 production\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 ...\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test\n\xe2\x94\x82       \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 ...\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 news\n\xe2\x94\x82       \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82       \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __main__.py\n\xe2\x94\x82       \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 app.py\n\xe2\x94\x82       \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 ...\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 tests\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .gitignore\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 poetry.lock\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 ...\n
Run Code Online (Sandbox Code Playgroud)\n

我的 python_server/Dockerfile

\n
FROM python:3.10.11-slim\n\nENV PYTHONDONTWRITEBYTECODE 1 \\\n    PYTHONUNBUFFERED 1\n\nRUN apt-get update \\\n    && apt-get install --no-install-recommends -y gcc libffi-dev g++\\\n    && apt-get clean \\\n    && rm -rf /var/lib/apt/lists/*\n\nENV POETRY_VERSION=1.5.0\n\nRUN pip install "poetry==$POETRY_VERSION"\n\nRUN groupadd --gid 10000 ch_news \\\n    && useradd --uid 10000 --gid ch_news --shell /bin/bash --create-home ch_news\n\nWORKDIR /home/ch_news\n\nCOPY --chown=10000:10000 pyproject.toml poetry.lock ./\n\nUSER ch_news\n\nRUN poetry install --no-root --no-ansi --without dev\n\nCOPY --chown=10000:10000 ./src ./\n\nCMD ["poetry", "run", "news"]\n
Run Code Online (Sandbox Code Playgroud)\n

我的 docker-compose 文件

\n
version: '3.9' # optional since v1.27.0\nname: ch_news_dev\nservices:\n  ...\n\n  ch_news_dev_python:\n    build:\n      context: ../..\n      dockerfile: ./docker/development/python_server/Dockerfile\n    container_name: ch_news_dev_python\n    depends_on:\n      ch_news_dev_postgres:\n        condition: service_healthy\n    env_file:\n      - .env\n    image: ch_news_dev_python_image\n    networks:\n      - network\n    restart: 'always'\n    volumes:\n      - postgres_certs:/home/ch_news/certs\n\nnetworks:\n  network:\n    driver: bridge\n\nvolumes:\n  postgres_certs:\n    driver: local\n  postgres_data:\n    driver: local\n
Run Code Online (Sandbox Code Playgroud)\n

我的 pyproject.toml 文件

\n
[tool.poetry]\nauthors = ["..."]\ndescription = "..."\nname = "news"\nversion = "0.1.0"\n\n[tool.poetry.dependencies]\nfeedparser = "^6.0.10"\npython = "^3.10"\naiohttp = "^3.8.4"\npython-dateutil = "^2.8.2"\nasyncpg = "^0.27.0"\nloguru = "^0.7.0"\n\n[tool.poetry.dev-dependencies]\ncommitizen = "^3.2.2"\npre-commit = "^3.3.2"\npytest = "^7.3.1"\npytest-cov = "^4.0.0"\ntox = "^4.5.1"\n\nbandit = "^1.7.5"\nblack = "^23.3.0"\ndarglint = "^1.8.1"\nflake8 = "^6.0.0"\nflake8-bugbear = "^23.5.9"\nflake8-docstrings = "^1.7.0"\nisort = "^5.12.0"\nmypy = "^1.3.0"\npytest-clarity = "^1.0.1"\npytest-sugar = "^0.9.7"\ntypeguard = "^4.0.0"\nxdoctest = "^1.1.0"\naioresponses = "^0.7.4"\npytest-asyncio = "^0.21.0"\ntypes-python-dateutil = "^2.8.19"\n\n[tool.poetry.group.dev.dependencies]\nisort = "^5.12.0"\ntypes-python-dateutil = "^2.8.19.7"\nflake8-docstrings = "^1.7.0"\nxdoctest = "^1.1.1"\npre-commit = "^3.3.2"\ncommitizen = "^3.2.2"\ntox = "^4.5.1"\nmypy = "^1.3.0"\npytest = "^7.3.1"\nflake8-bugbear = "^23.5.9"\nblack = "^23.3.0"\npytest-asyncio = "^0.21.0"\nbandit = "^1.7.5"\ntypeguard = "^4.0.0"\npytest-sugar = "^0.9.7"\n\n[tool.coverage.run]\nbranch = true\nomit = ["src/news/__main__.py", "src/news/app.py"]\nsource = ["news"]\n\n[tool.pytest.ini_options]\npythonpath = "src"\naddopts = [\n    "--import-mode=importlib",\n]\n\n[tool.coverage.report]\nfail_under = 95\n\n[tool.isort]\nprofile = "black"\nsrc_paths = ["src", "tests"]\nskip_gitignore = true\nforce_single_line = true\natomic = true\ncolor_output = true\n\n[tool.mypy]\npretty = true\nshow_column_numbers = true\nshow_error_codes = true\nshow_error_context = true\nignore_missing_imports = true\nstrict = true\nwarn_unreachable = true\n\n[tool.poetry.scripts]\nnews = "news.__main__:app"\n\n[tool.commitizen]\nname = "cz_conventional_commits"\ntag_format = "v$major.$minor.$patch$prerelease"\nversion = "0.0.1"\n[build-system]\nbuild-backend = "poetry.core.masonry.api"\nrequires = ["poetry-core>=1.0.0"]\n
Run Code Online (Sandbox Code Playgroud)\n

有人可以告诉我如何摆脱这个警告吗?

\n

更新1

\n

即使删除 --no-root 后仍收到警告

\n

小智 3

该错误与以下事实有关:入口点是在文件 pyproject.toml 中以诗歌形式声明的:

[tool.poetry.scripts]
news = "news.__main__:app"
Run Code Online (Sandbox Code Playgroud)

声明入口点后,必须执行命令

poetry install
Run Code Online (Sandbox Code Playgroud)

在你的终端中

  • `poetry install` 什么也不做。我仍然收到错误。 (7认同)