Как обновить альтернативы Python 3, не нарушая apt?Python

Программы на Python
Anonymous
 Как обновить альтернативы Python 3, не нарушая apt?

Сообщение Anonymous »

На днях я решил, что хочу, чтобы команда python по умолчанию запускала python3 вместо python2.

Итак, я сделал следующее:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 3

$ sudo update-alternatives --config python

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 3 auto mode
1 /usr/bin/python2.7 2 manual mode
2 /usr/bin/python3.5 3 manual mode

Press to keep the current choice[*], or type selection number: 0


И все это сработало. Большой! :)

$ python -V
Python 3.5.2


Но вскоре я понял, что сломал apt/aptitude, когда дело дошло до установки и удаления пакетов Python, потому что apt ожидал, что это произойдет на python2.

Вот что и произошло.

$ sudo apt remove python-samba
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
samba-libs
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
python-samba
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 5,790 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 187285 files and directories currently installed.)
Removing python-samba (2:4.3.11+dfsg-0ubuntu0.16.04.5) ...
File "/usr/bin/pyclean", line 63
except (IOError, OSError), e:
^
SyntaxError: invalid syntax
dpkg: error processing package python-samba (--remove):
subprocess installed pre-removal script returned error exit status 1
Traceback (most recent call last):
File "/usr/bin/pycompile", line 35, in
from debpython.version import SUPPORTED, debsorted, vrepr, \
File "/usr/share/python/debpython/version.py", line 24, in
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: error while cleaning up:
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
python-samba
E: Sub-process /usr/bin/dpkg returned an error code (1)


В конце концов я догадался, что Python2 нужен по умолчанию, поэтому я отменил свои изменения следующим образом:

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 3 auto mode
1 /usr/bin/python2.7 2 manual mode
2 /usr/bin/python3.5 3 manual mode

Press to keep the current choice[*], or type selection number: 1

$ python -V
Python 2.7.12


И затем apt снова заработал

$ sudo apt remove python-samba
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
samba-libs
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
python-samba
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 5,790 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 187285 files and directories currently installed.)
Removing python-samba (2:4.3.11+dfsg-0ubuntu0.16.04.5) ...


Поэтому мне пришлось оставить значение по умолчанию для Python 2, но я разрабатываю на Python 3 и поэтому хотел бы, чтобы моя система по умолчанию использовала Python 3, когда я запускаю Python и простаиваю.

Может ли кто-нибудь сказать мне, как я могу добиться этого, не нарушая apt?

Моя система — Raspberry Pi 3B под управлением Ubuntu:

Linux mymachine 4.4.38-v7+ #938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l armv7l armv7l GNU/Linux


(На самом деле это рука v8)

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"


Подробнее здесь: https://stackoverflow.com/questions/430 ... eaking-apt

Вернуться в «Python»