pip 不起作用/重新安装 pip 返回错误

pip 不起作用/重新安装 pip 返回错误

我最近尝试使用 pip 安装软件包,当我输入 pip install... 命令并按回车键时,什么也没发生,该过程似乎停止了或在循环运行。没有输入,我关闭了终端。

与此同时,我更新了 python。我怀疑我可能做错了什么,但作为终端新手,我不确定可能出了什么问题。

我想我应该尝试重新安装 pip,但返回了下面给出的错误。

知道该去哪里调查吗?

$ sudo apt-get install python-pip
[sudo] password for benoit: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-pip is already the newest version (8.1.1-2ubuntu0.4).
The following packages were automatically installed and are no longer required:
  libgles1-mesa linux-headers-4.8.0-36 linux-headers-4.8.0-36-generic
  linux-headers-4.8.0-39 linux-headers-4.8.0-39-generic linux-headers-4.8.0-41
  linux-headers-4.8.0-41-generic linux-headers-4.8.0-45
  linux-headers-4.8.0-45-generic linux-headers-4.8.0-46
  linux-headers-4.8.0-46-generic linux-headers-4.8.0-49
  linux-headers-4.8.0-49-generic linux-image-4.8.0-36-generic
  linux-image-4.8.0-39-generic linux-image-4.8.0-41-generic
  linux-image-4.8.0-45-generic linux-image-4.8.0-46-generic
  linux-image-4.8.0-49-generic linux-image-extra-4.8.0-36-generic
  linux-image-extra-4.8.0-39-generic linux-image-extra-4.8.0-41-generic
  linux-image-extra-4.8.0-45-generic linux-image-extra-4.8.0-46-generic
  linux-image-extra-4.8.0-49-generic snap-confine
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  python3-update-manager update-manager
The following packages will be upgraded:
  python3-update-manager update-manager
2 upgraded, 0 newly installed, 0 to remove and 61 not upgraded.
48 not fully installed or removed.
Need to get 0 B/575 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 420706 files and directories currently installed.)
Preparing to unpack .../python3-update-manager_1%3a16.04.6_all.deb ...
  File "/usr/bin/py3clean", line 4
SyntaxError: Non-ASCII character '\xc2' in file /usr/bin/py3clean on line 4, but no encoding declared; see python.org/dev/peps/pep-0263/ for details
dpkg: warning: subprocess old pre-removal script returned error exit status 1
dpkg: trying script from the new package instead ...
  File "/usr/bin/py3clean", line 4
SyntaxError: Non-ASCII character '\xc2' in file /usr/bin/py3clean on line 4, but no encoding declared; see python.org/dev/peps/pep-0263/ for details
dpkg: error processing archive /var/cache/apt/archives/python3-update-manager_1%3a16.04.6_all.deb (--unpack):
 subprocess new pre-removal script returned error exit status 1
  File "/usr/bin/py3compile", line 4
SyntaxError: Non-ASCII character '\xc2' in file /usr/bin/py3compile on line 4, but no encoding declared; see python.org/dev/peps/pep-0263/ for details
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Preparing to unpack .../update-manager_1%3a16.04.6_all.deb ...
  File "/usr/bin/py3clean", line 4
SyntaxError: Non-ASCII character '\xc2' in file /usr/bin/py3clean on line 4, but no encoding declared; see python.org/dev/peps/pep-0263/ for details
dpkg: warning: subprocess old pre-removal script returned error exit status 1
dpkg: trying script from the new package instead ...
  File "/usr/bin/py3clean", line 4
SyntaxError: Non-ASCII character '\xc2' in file /usr/bin/py3clean on line 4, but no encoding declared; see python.org/dev/peps/pep-0263/ for details
dpkg: error processing archive /var/cache/apt/archives/update-manager_1%3a16.04.6_all.deb (--unpack):
 subprocess new pre-removal script returned error exit status 1
  File "/usr/bin/py3compile", line 4
SyntaxError: Non-ASCII character '\xc2' in file /usr/bin/py3compile on line 4, but no encoding declared; see python.org/dev/peps/pep-0263/ for details
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/python3-update-manager_1%3a16.04.6_all.deb
 /var/cache/apt/archives/update-manager_1%3a16.04.6_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

这是我得到的

/$ sudo apt-get update

Hit:1 archive.canonical.com/ubuntu xenial InRelease
Get:2 ppa.launchpad.net/otto-kesselgulasch/gimp/ubuntu xenial InRelease [17,5 kB]            
Hit:3 ca.archive.ubuntu.com/ubuntu xenial InRelease                                          
Hit:4 ca.archive.ubuntu.com/ubuntu xenial-security InRelease                                 
Hit:5 ppa.launchpad.net/teejee2008/ppa/ubuntu xenial InRelease                               
Ign:6 repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 InRelease                           
Hit:7 repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 Release  
Ign:8 dl.google.com/linux/chrome/deb stable InRelease            
Ign:9 dl.google.com/linux/earth/deb stable InRelease
Ign:10 dl.google.com/linux/talkplugin/deb stable InRelease
Ign:2 ppa.launchpad.net/otto-kesselgulasch/gimp/ubuntu xenial InRelease
Hit:11 dl.google.com/linux/chrome/deb stable Release
Hit:12 dl.google.com/linux/earth/deb stable Release
Hit:15 dl.google.com/linux/talkplugin/deb stable Release
Fetched 17,5 kB in 0s (29,9 kB/s)                 
Reading package lists... Done
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:24 and /etc/apt/sources.list.d/google-chrome.list:3
...
W: Target DEP-11-icons (main/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:24 and /etc/apt/sources.list.d/google-chrome.list:3

即使我重新生成了 sources.list,我仍然收到上述错误,现在的情况如下:

源列表

答案1

还有另一种简单的方法,即使用 Curl 和 python 安装 pip。

sudo apt-get update

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"

python get-pip.py

现在验证 pip 安装:在终端上写入 pip。你可以看到一些代码。

如果你想检查版本

pip -V

相关内容