question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to install using python 3 on clean Ubuntu 18.04 image

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
jonapichcommented, Jan 8, 2020

@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.

5reactions
finswimmercommented, Jan 8, 2020

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 no python. At the moment, poetry expects that there is a python within the path. It doesn’t matter if it links to a python2 or python3. So I install python2 by sudo apt-get install python. After that it looks like this

$ which python
/usr/bin/python

$ python --version
Python 2.7.17

$ which python2
/usr/bin/python2

$ python2 --version
Python 2.7.17

$ which python3
/usr/bin/python3

$ python3 --version
Python 3.6.9

For installing poetry, curl is needed:

sudo apt-get install curl

Then:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

Now let’s create two poetry projects. One that should use python2 and one python3.

mkdir project_python2
cd project_python2
poetry init --no-interaction

The pyproject.toml looks like this:

[tool.poetry]
name = "project_python2"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^2.7"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

Now install the project:

$ poetry install

And you’re done. Whenever running a poetry command you will receive a warning like this:

/home/finswimmer/.poetry/lib/poetry/_vendor/py2.7/subprocess32.py:149: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads.  "program uses threads.", RuntimeWarning)

It’s a warning and AFAIK you can ignore it.

Now let’s see what happens for a project uses python3. Copy the above pyproject.toml to a new folder called project_python3. Change the name in this file to match the folder name and change python = "^2.7" to python = "^3.6".

Run poetry install and you may receive an error message that you need to install python3-venv. Ok, let’s do it:

$ sudo apt-get install python3-venv

Unfortunately poetry left a broken venv behind, we had to remove before trying again.

$ poetry env remove python3

and

$ poetry install
$ poetry run python --version
Python 3.6.9

To summarize:

  • make sure there is a python
  • it doesn’t matter if python links to python2 or python3
  • in addition to python there should be python2 and python3 in your path, if you like to use different python3 versions in different project. Because poetry tries the one or the other if the version of python doesn’t match the project’s python version
  • You may need to install python3-venv. But poetry will complain about it if needed.

fin swimmer

Read more comments on GitHub >

github_iconTop Results From Across the Web

docker - Can I install python 3.7 in ubuntu 18.04 without ...
This would fail as python3.7-pip doesn't seem to exist; only python3-pip does, which is what installs python 3.6 for some reason. I tried...
Read more >
How to upgrade to Python 3.10 on Ubuntu 18.04 and 20.04 LTS
Step 1: Add the repository and update · Step 2: Install the Python 3.10 package using apt-get · Step 3: Add Python 3.8...
Read more >
"Unable to locate package" while trying to install ... - Ask Ubuntu
First, check if the package actually does exist: Go to packages.ubuntu.com with a web browser. Scroll down to "Search package directories".
Read more >
How to Install Pip on Ubuntu 20.04 & 18.04 [Super Easy Way]
Python 2 is deprecated and not available in Ubuntu 20.04 and higher versions. You can only install PIP3. First, make sure that Python...
Read more >
How to Install Pyenv on Ubuntu 18.04 - Liquid Web
Now for further verification, change the version of Python to 3.8.3 and drop into a python shell. root@ubuntu:~# pyenv global 3.8.3 root@ubuntu ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found