Closed karambaq closed 7 months ago
I don't know what's going on here but I'd bet against it being a poetry bug. If poetry run
simply didn't work then there would have been more reports than just this.
Perhaps you have an unhelpful shebang in your manage.py
? But I am just guessing, you will have to work out for yourself what is going on. Recommend that "it's probably not a poetry bug" is a reasonable prior for you to adopt in that investigation.
@karambaq, by default poetry creates a virtualenv so you should either use the virtualenv is creates or disable virtualenv creation with something like poetry config virtualenvs.create false --local
. You can read about it more here.
Hence, the reason why your app cannot find the django installation is because your app is using the container default interpreter where poetry creates a virtualenv based on the container default interpreter and installs the packages there.
This issue cannot be reproduced, and it would seem this is an issue specific to the project being developed.
Here is an example of a working example of using a Django project with Poetry. See logs below.
podman run --rm -i -p 8000:8000 --entrypoint bash docker.io/python:3.12 <<EOF
set -xe
python -m pip install --disable-pip-version-check -q poetry
poetry config virtualenvs.in-project true
poetry config virtualenvs.options.no-pip true
poetry config virtualenvs.options.no-setuptools true
poetry new demo
pushd demo
poetry add Django
poetry run python -m django --version
poetry run django-admin startproject mysite
poetry run python mysite/manage.py migrate
# this is since we are running without a tty
export PYTHONUNBUFFERED=1
poetry run python mysite/manage.py runserver
EOF
```console + python -m pip install --disable-pip-version-check -q poetry WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv + poetry config virtualenvs.in-project true + poetry config virtualenvs.options.no-pip true + poetry config virtualenvs.options.no-setuptools true + poetry new demo Created package demo in demo + pushd demo /demo / + poetry add Django Creating virtualenv demo in /demo/.venv Using version ^5.0.3 for django Updating dependencies Resolving dependencies... Package operations: 3 installs, 0 updates, 0 removals - Installing asgiref (3.8.1) - Installing sqlparse (0.4.4) - Installing django (5.0.3) Writing lock file + poetry run python -m django --version 5.0.3 + poetry run django-admin startproject mysite + poetry run python mysite/manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying auth.0012_alter_user_first_name_max_length... OK Applying sessions.0001_initial... OK + export PYTHONUNBUFFERED=1 + PYTHONUNBUFFERED=1 + poetry run python mysite/manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). March 23, 2024 - 00:07:30 Django version 5.0.3, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. ```
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Poetry version: 1.4.0
Python version: Poetry: 3.10.10, System & Venv: 3.10.5
OS version and name: MacOS Ventura 13.0
pyproject.toml: https://gist.github.com/karambaq/6909c7b5447d13676ac62ff28efa89c6
[x] I am on the latest stable Poetry version, installed using a recommended method.
[x] I have searched the issues of this repo and believe that this is not a duplicate.
[x] I have consulted the FAQ and blog for any relevant entries or release notes.
[x] If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option) and have included the output below.Issue
I'm trying to run it from docker, here is my dockerfile:
dockerfile
```docker FROM python:3.9 ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 RUN apt-get update \ ... ARG UID ARG GID RUN groupadd -g $GID -o django RUN useradd -u $UID -g $GID -o -s /bin/bash -m django RUN mkdir -p /app/code /app/requirements && chown -R django:django /app COPY ./_compose/app/scripts/start-django / RUN chmod +x /start-django # COPY ./requirements /app/requirements # RUN pip install -r /app/requirements/local.txt COPY poetry.lock pyproject.toml ./ RUN pip3 install poetry RUN poetry install --only main USER django WORKDIR /app/code ```
And this is my script to start django:
Output of the script when I'm trying to start it:
Error: