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]`
Question:
- I am trying to run my poetry based python project inside docker using docker compose
- When I run the application, it works but it gives me this warning
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]`.
ch_news_dev_python |
ch_news_dev_python | The support to run uninstalled scripts will be removed in a future release.
ch_news_dev_python |
ch_news_dev_python | Run `poetry install` to resolve and get rid of this message.
My project structure
news
├── docker
│ ├── development
│ │ ├── ...
│ │ ├── python_server
│ │ │ └── Dockerfile
│ │ ├── .env
│ │ └── docker-compose.yml
│ ├── production
│ │ └── ...
│ └── test
│ └── ...
├── src
│ └── news
│ ├── __init__.py
│ ├── __main__.py
│ ├── app.py
│ └── ...
├── tests
├── .gitignore
├── pyproject.toml
├── poetry.lock
└── ...
My python_server/Dockerfile
FROM python:3.10.11-slim
ENV PYTHONDONTWRITEBYTECODE 1
PYTHONUNBUFFERED 1
RUN apt-get update
&& apt-get install --no-install-recommends -y gcc libffi-dev g++
&& apt-get clean
&& rm -rf /var/lib/apt/lists/*
ENV POETRY_VERSION=1.5.0
RUN pip install "poetry==$POETRY_VERSION"
RUN groupadd --gid 10000 ch_news
&& useradd --uid 10000 --gid ch_news --shell /bin/bash --create-home ch_news
WORKDIR /home/ch_news
COPY --chown=10000:10000 pyproject.toml poetry.lock ./
USER ch_news
RUN poetry install --no-root --no-ansi --without dev
COPY --chown=10000:10000 ./src ./
CMD ["poetry", "run", "news"]
My docker-compose file
version: '3.9' # optional since v1.27.0
name: ch_news_dev
services:
...
ch_news_dev_python:
build:
context: ../..
dockerfile: ./docker/development/python_server/Dockerfile
container_name: ch_news_dev_python
depends_on:
ch_news_dev_postgres:
condition: service_healthy
env_file:
- .env
image: ch_news_dev_python_image
networks:
- network
restart: 'always'
volumes:
- postgres_certs:/home/ch_news/certs
networks:
network:
driver: bridge
volumes:
postgres_certs:
driver: local
postgres_data:
driver: local
My pyproject.toml file
[tool.poetry]
authors = ["..."]
description = "..."
name = "news"
version = "0.1.0"
[tool.poetry.dependencies]
feedparser = "^6.0.10"
python = "^3.10"
aiohttp = "^3.8.4"
python-dateutil = "^2.8.2"
asyncpg = "^0.27.0"
loguru = "^0.7.0"
[tool.poetry.dev-dependencies]
commitizen = "^3.2.2"
pre-commit = "^3.3.2"
pytest = "^7.3.1"
pytest-cov = "^4.0.0"
tox = "^4.5.1"
bandit = "^1.7.5"
black = "^23.3.0"
darglint = "^1.8.1"
flake8 = "^6.0.0"
flake8-bugbear = "^23.5.9"
flake8-docstrings = "^1.7.0"
isort = "^5.12.0"
mypy = "^1.3.0"
pytest-clarity = "^1.0.1"
pytest-sugar = "^0.9.7"
typeguard = "^4.0.0"
xdoctest = "^1.1.0"
aioresponses = "^0.7.4"
pytest-asyncio = "^0.21.0"
types-python-dateutil = "^2.8.19"
[tool.poetry.group.dev.dependencies]
isort = "^5.12.0"
types-python-dateutil = "^2.8.19.7"
flake8-docstrings = "^1.7.0"
xdoctest = "^1.1.1"
pre-commit = "^3.3.2"
commitizen = "^3.2.2"
tox = "^4.5.1"
mypy = "^1.3.0"
pytest = "^7.3.1"
flake8-bugbear = "^23.5.9"
black = "^23.3.0"
pytest-asyncio = "^0.21.0"
bandit = "^1.7.5"
typeguard = "^4.0.0"
pytest-sugar = "^0.9.7"
[tool.coverage.run]
branch = true
omit = ["src/news/__main__.py", "src/news/app.py"]
source = ["news"]
[tool.pytest.ini_options]
pythonpath = "src"
addopts = [
"--import-mode=importlib",
]
[tool.coverage.report]
fail_under = 95
[tool.isort]
profile = "black"
src_paths = ["src", "tests"]
skip_gitignore = true
force_single_line = true
atomic = true
color_output = true
[tool.mypy]
pretty = true
show_column_numbers = true
show_error_codes = true
show_error_context = true
ignore_missing_imports = true
strict = true
warn_unreachable = true
[tool.poetry.scripts]
news = "news.__main__:app"
[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "v$major.$minor.$patch$prerelease"
version = "0.0.1"
[build-system]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0"]
Can someone kindly tell me how to get rid of this warning?
UPDATE 1
Getting the warning even after removing –no-root
Answers:
You docker file shows, that you are running poetry install
with the --no-root
flag. Entrypoints are part of your package, so they get only installed when the package is installed as well. You have to run poetry install
without the --no-root
flag.
I don’t see any reason, why you are using --no-root
. Without installing the project itself, it’s just luck that your import
statements are working.
the error is related to the fact that the entry point is declared in poetry
in your file pyproject.toml :
[tool.poetry.scripts]
news = "news.__main__:app"
after declaring the entry point, you must execute the command
poetry install
in your terminal
Name of src directory in project should be the same as name in toml (4th line of pyproject.toml
)
So you should rename your src directory to "news"
. Or (as an option) you can change name = "news"
to 'name = "src"'
in 4th line of your toml.
- I am trying to run my poetry based python project inside docker using docker compose
- When I run the application, it works but it gives me this warning
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]`.
ch_news_dev_python |
ch_news_dev_python | The support to run uninstalled scripts will be removed in a future release.
ch_news_dev_python |
ch_news_dev_python | Run `poetry install` to resolve and get rid of this message.
My project structure
news
├── docker
│ ├── development
│ │ ├── ...
│ │ ├── python_server
│ │ │ └── Dockerfile
│ │ ├── .env
│ │ └── docker-compose.yml
│ ├── production
│ │ └── ...
│ └── test
│ └── ...
├── src
│ └── news
│ ├── __init__.py
│ ├── __main__.py
│ ├── app.py
│ └── ...
├── tests
├── .gitignore
├── pyproject.toml
├── poetry.lock
└── ...
My python_server/Dockerfile
FROM python:3.10.11-slim
ENV PYTHONDONTWRITEBYTECODE 1
PYTHONUNBUFFERED 1
RUN apt-get update
&& apt-get install --no-install-recommends -y gcc libffi-dev g++
&& apt-get clean
&& rm -rf /var/lib/apt/lists/*
ENV POETRY_VERSION=1.5.0
RUN pip install "poetry==$POETRY_VERSION"
RUN groupadd --gid 10000 ch_news
&& useradd --uid 10000 --gid ch_news --shell /bin/bash --create-home ch_news
WORKDIR /home/ch_news
COPY --chown=10000:10000 pyproject.toml poetry.lock ./
USER ch_news
RUN poetry install --no-root --no-ansi --without dev
COPY --chown=10000:10000 ./src ./
CMD ["poetry", "run", "news"]
My docker-compose file
version: '3.9' # optional since v1.27.0
name: ch_news_dev
services:
...
ch_news_dev_python:
build:
context: ../..
dockerfile: ./docker/development/python_server/Dockerfile
container_name: ch_news_dev_python
depends_on:
ch_news_dev_postgres:
condition: service_healthy
env_file:
- .env
image: ch_news_dev_python_image
networks:
- network
restart: 'always'
volumes:
- postgres_certs:/home/ch_news/certs
networks:
network:
driver: bridge
volumes:
postgres_certs:
driver: local
postgres_data:
driver: local
My pyproject.toml file
[tool.poetry]
authors = ["..."]
description = "..."
name = "news"
version = "0.1.0"
[tool.poetry.dependencies]
feedparser = "^6.0.10"
python = "^3.10"
aiohttp = "^3.8.4"
python-dateutil = "^2.8.2"
asyncpg = "^0.27.0"
loguru = "^0.7.0"
[tool.poetry.dev-dependencies]
commitizen = "^3.2.2"
pre-commit = "^3.3.2"
pytest = "^7.3.1"
pytest-cov = "^4.0.0"
tox = "^4.5.1"
bandit = "^1.7.5"
black = "^23.3.0"
darglint = "^1.8.1"
flake8 = "^6.0.0"
flake8-bugbear = "^23.5.9"
flake8-docstrings = "^1.7.0"
isort = "^5.12.0"
mypy = "^1.3.0"
pytest-clarity = "^1.0.1"
pytest-sugar = "^0.9.7"
typeguard = "^4.0.0"
xdoctest = "^1.1.0"
aioresponses = "^0.7.4"
pytest-asyncio = "^0.21.0"
types-python-dateutil = "^2.8.19"
[tool.poetry.group.dev.dependencies]
isort = "^5.12.0"
types-python-dateutil = "^2.8.19.7"
flake8-docstrings = "^1.7.0"
xdoctest = "^1.1.1"
pre-commit = "^3.3.2"
commitizen = "^3.2.2"
tox = "^4.5.1"
mypy = "^1.3.0"
pytest = "^7.3.1"
flake8-bugbear = "^23.5.9"
black = "^23.3.0"
pytest-asyncio = "^0.21.0"
bandit = "^1.7.5"
typeguard = "^4.0.0"
pytest-sugar = "^0.9.7"
[tool.coverage.run]
branch = true
omit = ["src/news/__main__.py", "src/news/app.py"]
source = ["news"]
[tool.pytest.ini_options]
pythonpath = "src"
addopts = [
"--import-mode=importlib",
]
[tool.coverage.report]
fail_under = 95
[tool.isort]
profile = "black"
src_paths = ["src", "tests"]
skip_gitignore = true
force_single_line = true
atomic = true
color_output = true
[tool.mypy]
pretty = true
show_column_numbers = true
show_error_codes = true
show_error_context = true
ignore_missing_imports = true
strict = true
warn_unreachable = true
[tool.poetry.scripts]
news = "news.__main__:app"
[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "v$major.$minor.$patch$prerelease"
version = "0.0.1"
[build-system]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0"]
Can someone kindly tell me how to get rid of this warning?
UPDATE 1
Getting the warning even after removing –no-root
You docker file shows, that you are running poetry install
with the --no-root
flag. Entrypoints are part of your package, so they get only installed when the package is installed as well. You have to run poetry install
without the --no-root
flag.
I don’t see any reason, why you are using --no-root
. Without installing the project itself, it’s just luck that your import
statements are working.
the error is related to the fact that the entry point is declared in poetry
in your file pyproject.toml :
[tool.poetry.scripts]
news = "news.__main__:app"
after declaring the entry point, you must execute the command
poetry install
in your terminal
Name of src directory in project should be the same as name in toml (4th line of pyproject.toml
)
So you should rename your src directory to "news"
. Or (as an option) you can change name = "news"
to 'name = "src"'
in 4th line of your toml.