Following the indications found here: https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-repository I'm trying to install Docker Engine in Ubuntu 18.04.02 Server Edition.
The first installation's steps went fine but I encountered this error message:
(base) marco@pc:~$ sudo add-apt-repository \
> "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) \
> stable"
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties,
shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties
/SoftwareProperties.py", line 67, in <module>
from gi.repository import Gio
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in
<module>
from . import _gi
ImportError: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-
packages/gi/__init__.py)
But import gi in python3 works fine:
(base) marco@pc:~$ python3
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>>
Updates:
1) after modifying the very first line of /usr/bin/add-apt-repository to #!/usr/bin/python3.7.3
(base) marco@pc:~$ sudo add-apt-repository \
> "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) \
> stable"
sudo: unable to execute /usr/bin/add-apt-repository: No such file or
directory
2) I installed python 3.7.3 following the indications found here:
https://linoxide.com/linux-how-to/install-python-ubuntu/ and here: https://www.how2shout.com/how-to/install-python-on-ubuntu-19-04-18-04-using-command-terminal.html
(base) marco@pc:~$ ls -al /usr/bin | grep python
lrwxrwxrwx 1 root root 26 Mar 26 2018 dh_pypy -> ../share/dh-
python/dh_pypy
-rwxr-xr-x 1 root root 1056 Apr 16 2018 dh_python2
lrwxrwxrwx 1 root root 29 Mar 26 2018 dh_python3 -> ../share
/dh-python/dh_python3
lrwxrwxrwx 1 root root 23 Oct 7 19:39 pdb2.7 -> ../lib
/python2.7/pdb.py
lrwxrwxrwx 1 root root 23 Oct 7 14:59 pdb3.6 -> ../lib
/python3.6/pdb.py
lrwxrwxrwx 1 root root 23 Apr 3 2019 pdb3.7 -> ../lib
/python3.7/pdb.py
lrwxrwxrwx 1 root root 31 Jul 30 19:24 py3versions -> ../share
/python3/py3versions.py
lrwxrwxrwx 1 root root 26 Mar 26 2018 pybuild -> ../share/dh-
python/pybuild
lrwxrwxrwx 1 root root 9 Apr 16 2018 python -> python2.7
lrwxrwxrwx 1 root root 16 Apr 16 2018 python-config ->
python2.7-config
lrwxrwxrwx 1 root root 9 Apr 16 2018 python2 -> python2.7
lrwxrwxrwx 1 root root 16 Apr 16 2018 python2-config ->
python2.7-config
-rwxr-xr-x 1 root root 399 Nov 15 2017 python2-jsonschema
-rwxr-xr-x 1 root root 154 Nov 11 2017 python2-pbr
-rwxr-xr-x 1 root root 5901 Jul 27 2017 python2-wsdump
-rwxr-xr-x 1 root root 3641704 Oct 7 19:39 python2.7
lrwxrwxrwx 1 root root 33 Oct 7 19:39 python2.7-config ->
x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 25 Aug 11 10:46 python3 ->
/etc/alternatives/python3
lrwxrwxrwx 1 root root 16 Oct 25 2018 python3-config ->
python3.6-config
-rwxr-xr-x 1 root root 384 Feb 5 2018 python3-futurize
-rwxr-xr-x 1 root root 388 Feb 5 2018 python3-pasteurize
-rwxr-xr-x 1 root root 152 Nov 11 2017 python3-pbr
-rwxr-xr-x 2 root root 4526456 Oct 7 14:59 python3.6
lrwxrwxrwx 1 root root 33 Oct 7 14:59 python3.6-config ->
x86_64-linux-gnu-python3.6-config
-rwxr-xr-x 2 root root 4526456 Oct 7 14:59 python3.6m
lrwxrwxrwx 1 root root 34 Oct 7 14:59 python3.6m-config ->
x86_64-linux-gnu-python3.6m-config
-rwxr-xr-x 2 root root 4906512 Apr 3 2019 python3.7
-rwxr-xr-x 2 root root 4906512 Apr 3 2019 python3.7m
lrwxrwxrwx 1 root root 10 Jul 30 19:24 python3m -> python3.6m
lrwxrwxrwx 1 root root 17 Oct 25 2018 python3m-config ->
python3.6m-config
lrwxrwxrwx 1 root root 29 Apr 16 2018 pyversions -> ../share
/python/pyversions.py
lrwxrwxrwx 1 root root 33 Apr 16 2018 x86_64-linux-gnu-
python-config -> x86_64-linux-gnu-python2.7-config
-rwxr-xr-x 1 root root 2971 Oct 7 19:39 x86_64-linux-gnu-
python2.7-config
lrwxrwxrwx 1 root root 33 Oct 25 2018 x86_64-linux-gnu-
python3-config -> x86_64-linux-gnu-python3.6-config
lrwxrwxrwx 1 root root 34 Oct 7 14:59 x86_64-linux-gnu-
python3.6-config -> x86_64-linux-gnu-python3.6m-config
-rwxr-xr-x 1 root root 3283 Oct 7 14:59 x86_64-linux-gnu-
python3.6m-config
lrwxrwxrwx 1 root root 34 Oct 25 2018 x86_64-linux-gnu-
python3m-config -> x86_64-linux-gnu-python3.6m-config
(base) marco@pc:~$ which python3
/home/marco/anaconda3/bin/python3
(base) marco@pc:~$ python --version
Python 3.7.3
3) I modified the first line of /usr/bin/add-apt-repository:
(base) marco@pc:~$ head /usr/bin/add-apt-repository
#!/usr/bin/python3.7
from __future__ import print_function
Trying again to setup the stable Docker-Engine repository:
(base) marco@pc:~$ sudo add-apt-repository \
> "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) \
> stable"
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties,
shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties
/SoftwareProperties.py", line 67, in <module>
from gi.repository import Gio
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in
<module>
from . import _gi
ImportError: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-
packages/gi/__init__.py)
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 109,
in apport_excepthook
pr.add_proc_info(extraenv=['PYTHONPATH', 'PYTHONHOME'])
File "/usr/lib/python3/dist-packages/apport/report.py", line 543, in
add_proc_info
self.add_proc_environ(pid, extraenv)
File "/usr/lib/python3/dist-packages/apport/report.py", line 610, in
add_proc_environ
env = _read_file('environ', dir_fd=proc_pid_fd).replace('\n', '\\n')
File "/usr/lib/python3/dist-packages/apport/report.py", line 73, in
_read_file
with open(path, 'rb', opener=lambda path, mode: os.open(path, mode,
dir_fd=dir_fd)) as fd:
File "/usr/lib/python3/dist-packages/apport/report.py", line 73, in
<lambda>
with open(path, 'rb', opener=lambda path, mode: os.open(path, mode,
dir_fd=dir_fd)) as fd:
TypeError: argument should be integer or None, not list
Original exception was:
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties,
shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties
/SoftwareProperties.py", line 67, in <module>
from gi.repository import Gio
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in
<module>
from . import _gi
ImportError: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-
packages/gi/__init__.py)
And trying to update the python alternative:
(base) marco@pc:~$ update-alternatives --list python || update-
alternatives --list python
update-alternatives: error: no alternatives for python
update-alternatives: error: no alternatives for python
Following the indications found here: https://www.how2shout.com/how-to/install-python-on-ubuntu-19-04-18-04-using-command-terminal.html
I also tried to fix python3.7.3 as the official python in this way:
(base) marco@pc:~$ sudo update-alternatives --config python3.7.3
update-alternatives: error: no alternatives for python3.7.3
SOLVED:
Thanks to @Smurfz87 I discovered that python3.7.3 version causes this problem with apt-repository. After changing the first line of /usr/bin/add-apt-repository in order to point to 3.6 version : #!/usr/bin/python3.6 everything went fine:
(base) marco@pc:~$ sudo add-apt-repository \
> "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) \
> stable"
Hit:1 http://gb.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]
Get:3 http://gb.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7
kB]
Get:4 http://gb.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6
kB]
Get:5 https://download.docker.com/linux/ubuntu bionic/stable amd64
Packages [9594 B]
Get:6 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe i386
Packages [985 kB]
Get:7 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe amd64
Packages [1017 kB]
Hit:8 http://apt.postgresql.org/pub/repos/apt bionic-pgdg InRelease
Hit:9 http://ppa.launchpad.net/certbot/certbot/ubuntu bionic InRelease
Get:10 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7
kB]
Fetched 2328 kB in 11s (217 kB/s)
Reading package lists... Done
(base) marco@pc:~$ sudo apt-get update
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://apt.postgresql.org/pub/repos/apt bionic-pgdg InRelease
Hit:3 http://gb.archive.ubuntu.com/ubuntu bionic InRelease
Hit:4 http://gb.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://gb.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:6 http://ppa.launchpad.net/certbot/certbot/ubuntu bionic InRelease
Hit:7 https://download.docker.com/linux/ubuntu bionic InRelease
Reading package lists... Done
(base) marco@pc:~$ sudo apt-get install docker-ce docker-ce-cli
containerd.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
aufs-tools cgroupfs-mount pigz
The following NEW packages will be installed
aufs-tools cgroupfs-mount containerd.io docker-ce docker-ce-cli pigz
0 to upgrade, 6 to newly install, 0 to remove and 0 not to upgrade.
Need to get 85.6 MB of archives.
After this operation, 384 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Marco
Sounds like your system might have issues choosing the correct Python version. From dialog we established that you have a working version of Python 3.6.
Try editing the file
/usr/bin/add-apt-repository
and changing out the line#!/usr/bin/python3
with the specific version of python, in your case:#!/usr/bin/python3.6