poetry: Unable to install using python 3 on clean Ubuntu 18.04 image
I am trying to install poetry as early as possible in a clean docker run -it ubuntu:18.04
interactive session:
apt update
apt install python3 curl
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
at this point, poetry installed but won’t run because there’s no “python” on the system; only python3. so I made a symlink and tried again:
poetry --version
Traceback (most recent call last):
File "/root/.poetry/lib/poetry/_vendor/py3.6/keyring/backend.py", line 203, in _load_plugins
init_func = ep.load()
File "/root/.poetry/lib/poetry/_vendor/py3.6/importlib_metadata/__init__.py", line 92, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/lib/python3/dist-packages/keyrings/alt/Windows.py", line 9, in <module>
from . import file_base
File "/usr/lib/python3/dist-packages/keyrings/alt/file_base.py", line 13, in <module>
from keyring.util.escape import escape as escape_for_ini
ModuleNotFoundError: No module named 'keyring.util.escape'
I retried the steps using apt install python3-pip
followed by python3 -m pip install poetry
instead of the bootstrap script, but I get the same error when trying to run poetry.
What am I missing exactly?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 18 (11 by maintainers)
Commits related to this issue
- Don't swallow ImportError in temporary_directory() Fixes #3026 If the context wrapped by the temporary_directory() context manager raised ImportError (for example because distutils.util cannot be im... — committed to python-poetry/poetry by remram44 4 years ago
- Don't swallow ImportError in temporary_directory() Fixes #3026 If the context wrapped by the temporary_directory() context manager raised ImportError (for example because distutils.util cannot be im... — committed to abn/poetry by remram44 4 years ago
- Don't swallow ImportError in temporary_directory() (#3037) Fixes #3026 If the context wrapped by the temporary_directory() context manager raised ImportError (for example because distutils.util c... — committed to python-poetry/poetry by abn 4 years ago
@finswimmer thanks for double-checking; I already knew that python 2 worked to install it. The documentation is clear that it doesn’t matter which version of python is used to install poetry, so the scenario outlined in my original post (with python 3) is clearly an issue.
Using python 2 is not acceptable in my case; it’s simply not available on our production images and our
python
executable launches py3. Poetry absolutely have to be able to work in a python2-less environment.Hello,
I try to reproduce the problems mentioned here, by installing a fresh ubuntu 18.04 in a virtual machine. After doing this (installing the “minimal” variant), I ended up with a system where a
python3
exists but nopython
. At the moment,poetry
expects that there is apython
within the path. It doesn’t matter if it links to apython2
orpython3
. So I install python2 bysudo apt-get install python
. After that it looks like thisFor installing
poetry
,curl
is needed:Then:
Now let’s create two poetry projects. One that should use
python2
and onepython3
.The
pyproject.toml
looks like this:Now install the project:
And you’re done. Whenever running a
poetry
command you will receive a warning like this:It’s a warning and AFAIK you can ignore it.
Now let’s see what happens for a project uses
python3
. Copy the abovepyproject.toml
to a new folder calledproject_python3
. Change thename
in this file to match the folder name and changepython = "^2.7"
topython = "^3.6"
.Run
poetry install
and you may receive an error message that you need to installpython3-venv
. Ok, let’s do it:Unfortunately poetry left a broken venv behind, we had to remove before trying again.
and
To summarize:
python
python
links topython2
orpython3
python
there should bepython2
andpython3
in your path, if you like to use different python3 versions in different project. Becausepoetry
tries the one or the other if the version ofpython
doesn’t match the project’s python versionpython3-venv
. But poetry will complain about it if needed.fin swimmer
Get the same error when installing poetry using pip3 as well. Doesn’t seem to be a way to get 1.0.0 to use python3 at all, at least on ubuntu.
@jonapich this works for me at the moment; can you confirm please?
Note that that the ascii encoding error is an issuew ith the ubuntu docker image locale. In the above command I make use of
export PYTHONIOENCODING=utf-8
to make that work. See https://github.com/python-poetry/poetry/issues/1719#issuecomment-565391165.And the
distutils
requirement is expected to be available in a python install. I am not sure how Ubuntu is building their python package to comment on why it does not exist there.@pcgeek86 regarding
keyring.alt
issue, see https://github.com/python-poetry/poetry/issues/1719#issuecomment-565846793. The package is not required by poetry and hence should not be indicated as a dependency. This is a distro issue unfortunately and there is not clean fix that can be done from the poetry side for this one.See also: #1719
This issue also happens to Ubuntu 20.04
I’m not sure if this is the correct long-term fix for poetry, but do we need to add
keyrings.alt
to the list of poetry dependencies in this file? I can confirm that installing this package causes poetry to start working.https://github.com/python-poetry/poetry/blob/master/pyproject.toml#L52
I think I may have added a misstep in my original post… I tried my first scenario again and get a different result:
So I went ahead and
apt install python3-pip
. It’s a 110mb download with all its dependencies. Only then, I can reproduce the issue from my original post. (EDIT: you can also get python3-distutils which is a much smaller package; in both cases, we end up with the keyring callstack)I tried updating keyrings.alt as suggested. It seems to fix it, and then it breaks again later on:
I tried the same steps using python2 instead of python3. I get a different outcome: