Во время установки стабильного репозитория Механизма Докера в Выпуске Сервера Ubuntu 18.04.02: не может импортировать имя '_gi' из 'gi'

После признаков, найденных здесь: https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-repository я пытаюсь установить Механизм Докера в Выпуске Сервера Ubuntu 18.04.02.

Шаги первой установки пошли прекрасные, но я встретился с этим сообщением об ошибке:

(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)

Но импортируйте gi в python3, хорошо работает:

(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
>>> 

Обновления:

1) после изменения самой первой строки/usr/bin/add-apt-repository к #!/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) Я установил Python 3.7.3 после признаков, найденных здесь:

https://linoxide.com/linux-how-to/install-python-ubuntu/и здесь: 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) Я изменил первую строку/usr/bin/add-apt-repository:

(base) marco@pc:~$ head /usr/bin/add-apt-repository
#!/usr/bin/python3.7

from __future__ import print_function

Попробовав еще раз устанавливать стабильный репозиторий Механизма Докера:

(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)

И попытка обновить альтернативу Python:

(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

После признаков, найденных здесь: https://www.how2shout.com/how-to/install-python-on-ubuntu-19-04-18-04-using-command-terminal.html

Я также пытался зафиксировать python3.7.3 как официальный Python таким образом:

(base) marco@pc:~$ sudo update-alternatives --config python3.7.3
update-alternatives: error: no alternatives for python3.7.3

РЕШЕННЫЙ:

Благодаря @Smurfz87 я обнаружил, что python3.7.3 версия вызывает эту проблему со способным репозиторием. После изменения первой строки/usr/bin/add-apt-repository для указания на 3,6 версии: #!/usr/bin/python3.6 все пошло прекрасное:

(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

0
задан 30 October 2019 в 16:46

1 ответ

Кажется, что Ваша система могла бы иметь проблемы, выбирая корректную версию Python. От диалогового окна мы установили, что у Вас есть рабочая версия Python 3.6.

Попытайтесь редактировать файл /usr/bin/add-apt-repository и изменение строки #!/usr/bin/python3 с определенной версией Python, в Вашем случае:

#!/usr/bin/python3.6

1
ответ дан 23 December 2019 в 00:21

Другие вопросы по тегам:

Похожие вопросы: