Debian

debian9 無法使用 pip3 安裝 python 包或使用 apt 解除安裝包

  • June 21, 2021

您好,我是一個使用 Debian Stretch 的大 linux noobie。我在嘗試安裝包或刪除包時遇到錯誤。

這是我嘗試安裝軟體包時遇到的錯誤pip3

dsal3389@Dsal3389:~$ pip3 install django

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007f90b31f3740 (most recent call first):
Aborted

所以我後來嘗試刪除python3並安裝它,然後我得到了這個錯誤:

dsal3389@Dsal3389:~$ sudo apt purge python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
 diffstat distro-info-data espeak-ng-data gir1.2-accountsservice-1.0
 gir1.2-atspi-2.0 gir1.2-caribou-1.0 gir1.2-gck-1 gir1.2-gcr-3 gir1.2-gdm-1.0
 gir1.2-git2-glib-1.0 gir1.2-gmenu-3.0 gir1.2-gnomebluetooth-1.0
 gir1.2-grilo-0.3 gir1.2-gtk-2.0 gir1.2-gucharmap-2.90 gir1.2-mediaart-2.0
 gir1.2-mutter-3.0 gir1.2-networkmanager-1.0 gir1.2-nmgtk-1.0
 gir1.2-packagekitglib-1.0 gir1.2-polkit-1.0 gir1.2-rb-3.0 gir1.2-totem-1.0
 gir1.2-totem-plparser-1.0 gir1.2-upowerglib-1.0 gir1.2-vte-2.91
 gir1.2-wnck-3.0 gir1.2-zeitgeist-2.0 gnome-session-bin gnome-session-common
 gnome-software-common hyphen-en-us icu-devtools libappstream-glib8
 libapt-pkg-perl libbrlapi0.6 libc6-dev:i386 libcairo-script-interpreter2
 libcaribou-common libcaribou0 libcgi-fast-perl libcgi-pm-perl
 libclass-accessor-perl libclone-perl libdotconf0 libemail-valid-perl
 libespeak-ng1 libexporter-tiny-perl libfcgi-perl libfontconfig1-dev
 libfreetype6-dev libfwupd1 libgcab-1.0-0 libgdm1 libgit2-24
 libgit2-glib-1.0-0 libgnome-menu-3-0 libgpod-common libgpod4
 libgraphite2-dev libgspell-1-1 libgspell-1-common libgucharmap-2-90-7
 libharfbuzz-gobject0 libhttp-parser2.1 libice-dev libicu-dev libio-pty-perl
 libio-string-perl libipc-run-perl liblist-moreutils-perl liblouis-data
 liblouis12 libncursesw6 libnet-dns-perl libnet-domain-tld-perl
 libnet-ip-perl libnm-gtk0 libparse-debianchangelog-perl libpcaudio0
 libpcre3-dev libpcre32-3 libpcrecpp0v5 libperlio-gzip-perl libpixman-1-dev
 libpng-dev libpng-tools libpthread-stubs0-dev libpython3-dev
 libpython3-stdlib libpython3.5-dev libpython3.6-minimal libpython3.6-stdlib
 libreoffice-help-en-us libsgutils2-2 libsm-dev libsonic0 libspeechd2
 libsub-name-perl libtext-levenshtein-perl libtinfo6 libx11-dev libx11-doc
 libxau-dev libxcb-render0-dev libxcb-shm0-dev libxcb1-dev libxcomposite-dev
 libxcursor-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev
 libxft-dev libxi-dev libxinerama-dev libxrandr-dev libxrender-dev
 libyaml-libyaml-perl lintian linux-libc-dev:i386 patchutils pkg-config
 python-openssl python-requests python-urllib3 python3-minimal python3.5-dev
 python3.6-minimal speech-dispatcher speech-dispatcher-audio-plugins
 speech-dispatcher-espeak-ng t1utils x11proto-composite-dev x11proto-core-dev
 x11proto-damage-dev x11proto-fixes-dev x11proto-input-dev x11proto-kb-dev
 x11proto-randr-dev x11proto-render-dev x11proto-xext-dev
 x11proto-xinerama-dev xbrlapi xorg-sgml-doctools xtrans-dev xwayland
 zlib1g-dev
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
 apt-listchanges* caribou* chrome-gnome-shell* dh-python* gdebi* gdebi-core*
 gdm3* gedit* gedit-common* gedit-plugins* gir1.2-ibus-1.0* gnome*
 gnome-core* gnome-menus* gnome-music* gnome-orca* gnome-session*
 gnome-shell* gnome-shell-extensions* gnome-software* libatk1.0-dev*
 libcairo2-dev* libgdk-pixbuf2.0-dev* libglib2.0-dev* libgtk2.0-dev*
 libharfbuzz-dev* libpango1.0-dev* libreoffice* libreoffice-librelogo*
 libreoffice-script-provider-python* libxfce4util-dev* lsb-release* python3*
 python3-apt* python3-brlapi* python3-cairo* python3-cffi-backend*
 python3-chardet* python3-crypto* python3-cryptography* python3-cups*
 python3-cupshelpers* python3-dbus* python3-debian* python3-debianbts*
 python3-dev* python3-gi* python3-gi-cairo* python3-httplib2* python3-idna*
 python3-keyring* python3-keyrings.alt* python3-louis* python3-mako*
 python3-markupsafe* python3-pip* python3-pkg-resources* python3-pyasn1*
 python3-pyatspi* python3-pycurl* python3-pysimplesoap* python3-reportbug*
 python3-requests* python3-secretstorage* python3-setuptools* python3-six*
 python3-smbc* python3-software-properties* python3-speechd* python3-uno*
 python3-urllib3* python3-wheel* python3-xdg* reportbug* rhythmbox-plugins*
 software-properties-common* software-properties-gtk*
 system-config-printer-common* system-config-printer-udev*
 task-gnome-desktop* totem-plugins* ufw* unattended-upgrades* unoconv*
 xfce4-panel-dev*
0 upgraded, 0 newly installed, 85 to remove and 0 not upgraded.
After this operation, 118 MB disk space will be freed.
Do you want to continue? [Y/n] y
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007f04e1fbb740 (most recent call first):
Aborted
E: Sub-process /usr/bin/apt-listchanges --apt || test $? -lt 10 returned an >error code (1)
E: Failure running script /usr/bin/apt-listchanges --apt || test $? -lt 10

這只是發生了。打開我的電腦,得到了那些東西。

蟒蛇版本:

dsal3389@Dsal3389:~$ python3 -V
Python 3.5.3

包裹python3-pip有問題,可能會損壞apt

apt-listbugs list python3-pip
Retrieving bug reports... Done
Parsing Found/Fixed information... Done
serious bugs of python3-pip (-> ) <Resolved in some Version>
b1 - #896390 - python3-pip: pip fails to import (Fixed: python-pip/9.0.1-2.1)
Summary:
python3-pip(1 bug)

將 Python2.7 設置為預設值:

將 python* 添加到update-alternatives

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 40
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 30

切換到python2.7:

update-alternatives --config python

選擇python2.7。

僅刪除python3-pip包裝。

dpkg --configure -a
apt purge python3-pip

你可以保留python3:

apt --reinstall install python3

安裝apt-listbugs包一直跟踪python3-pip,bug修復後即可安裝。

編輯

按照@Faheem Mitha發布的這個答案來解決這個錯誤:

Could not find platform independent libraries <prefix> 
Could not find platform dependent libraries <exec_prefix> 
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] 

引用自:https://unix.stackexchange.com/questions/448226