poetry: Poetry with `virtualenvs.create false` installs packages into the wrong place on Ubuntu
- I am on the latest Poetry version.
- I have searched the issues of this repo and believe that this is not a duplicate.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).
- OS version and name: Ubuntu 20.04
- Poetry version: 1.2.0
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/amcinnes/8c61ad88b37a7740dd93efa976f85ed7
Issue
To reproduce the issue:
docker run --rm -it ubuntu:20.04@sha256:af5efa9c28de78b754777af9b4d850112cad01899a5d37d2617bb94dc63a49aa
apt-get update && apt-get -y install python3-pip
python3 -m pip install poetry==1.2.0
poetry config virtualenvs.create false
poetry init -n
poetry add awscli
aws --version
Expected behaviour (seen with poetry 1.1.14): the aws
command runs successfully.
# aws --version
aws-cli/1.25.70 Python/3.8.10 Linux/5.19.7-arch1-1 botocore/1.27.69
Observed behaviour (with poetry 1.2.0): the aws
command fails.
# aws --version
Traceback (most recent call last):
File "/usr/bin/aws", line 19, in <module>
import awscli.clidriver
ModuleNotFoundError: No module named 'awscli'
This seems to be because with poetry 1.2.0, awscli
has been installed into /usr/lib/python3.8/site-packages/awscli
which is not in the Python path.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 23
- Comments: 40 (16 by maintainers)
Adding to the argument by saying that I’d very much like to use official
tensorflow
docker images and they use system python. When adding my custom packages to the default install through poetry andvirtualenvs.create=false
it results in the bug described here.Using a virtual environment would defeat the purpose of using an image with everything pre-installed (including jupyter notebook).
+1 for this issue. We shouldn’t need to use a virtual environment inside a Docker image. I’m facing the issue when using an
ubuntu:22.04
base image withpoetry==1.3.1
. Making the settingpoetry config virtualenvs.create false
and then installing packages viapoetry install
results in packages being install in the wrong location. This was not an issue inpoetry==1.1.14
.Same issue for me
I’m running into this issue as well on Fedora 36
I see that the conversation has moved on quite a bit since this comment about the bug being an edge case, but I just wanted to push back on it a little bit: not only are Ubuntu and Debian a considerable portion of the total Linux space on their own, but also the official Python docker containers are built from Debian bullseye and buster (unless we want to use alpine). I would think poetry would hope to work out of the box with the official Python images.
Edit: not to say that it isn’t annoying that this issue has persisted for so long in those distros, but it really does seem like something poetry needs to be resilient to.
@neersighted Thanks for the feedback 😃
Of course there are workarounds, but it was working very seamlessly before. I think also using the term “virtual environment” is kind of misleading when one just wants to use the system Python environment. So the expecation of
poetry config virtualenvs.create false
would be that it’s using the actual system Python environment. Otherwise it might be even better to deprecate this option, so that it’s clear.(Finding out the correct path of the system Python environment is also not super easy 😄)
Any update on the fix for this bug?
Yes, or use poetry run
On Mon, Sep 12, 2022, 10:30 PM manojatlas @.***> wrote:
Is it hard to fix that? If you can give some pointers, maybe I can try?
It’s also causing issues with the Tensorflow images. And of course I don’t want a virtual environment there, since my Docker image will blow up with two TF installations. Plus, it is quite hacky to access the python executable from the created virtual environment in a script then.
The official Python images are just fine as they use a Python.org build of Python and not a patched/hacked distro-supplied Python. The edge case is mostly installing to system site-packages using a Debian-derived Python, which is definitely a thing people do, but is often ill-advised and will always be prone to sharp edges due to deviation from the standard Python ecosystem.
Looks like this is the old Debian patching of
distutils
without patchingsysconfig
acting up again, combined with our apparent failure to make use of our modified detection code:https://github.com/python-poetry/poetry/blob/c4b2253793cd6b41a99e25e479e40b776cca0a0e/src/poetry/utils/env.py#L193-L222
If I had to guess, it’s because we always treat the target environment as a
VirtualEnv
instead of aGenericEnv
and thus don’t invoke that script.Honestly, this is such an edge case (and mostly the result of bad Debian packaging) that I’m not sure there’s much value in fixing it – it’s easily resolved if you make use of a self-compiled Python or virtual environments (there is no reason to avoid them in a container, and doing so exposes you to all sorts of sharp edges like this).
This feels like another instance of #6398 – I would highly suggest looking at the pattern here https://github.com/python-poetry/poetry/issues/6397#issuecomment-1236327500 for something that is as ergonomic, but unlikely to be broken by distro packaging decisions.
Here is a tmp solution I used to set poetry env as the default python interpreter in docker.