Python 如何从pip冻结异常中恢复?

Python 如何从pip冻结异常中恢复?,python,python-2.7,ubuntu,pip,easy-install,Python,Python 2.7,Ubuntu,Pip,Easy Install,我正在Ubuntu14系统上安装Python2.7软件包,遇到了一个问题,“pip freeze”会产生这样的输出 $ pip freeze Exception: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/usr/lib

我正在Ubuntu14系统上安装Python2.7软件包,遇到了一个问题,“pip freeze”会产生这样的输出

$ pip freeze
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/freeze.py", line 74, in run
    req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 286, in from_dist
    assert len(specs) == 1 and specs[0][0] == '=='
AssertionError

Storing debug log for failure in /home/ubuntu/.pip/pip.log


$ cat /home/ubuntu/.pip/pip.log
------------------------------------------------------------
/usr/bin/pip run on Tue Feb  9 21:00:36 2016
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/freeze.py", line 74, in run
    req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 286, in from_dist
    assert len(specs) == 1 and specs[0][0] == '=='
AssertionError
我不确定是什么导致了这种情况。
我怀疑easy_install程序的失败可能导致某些东西损坏

我已尝试重新安装pip。
这没有效果

我怀疑我必须通过pip完成所有python软件包的卸载和重新安装,并通过apt get完成与python相关的ubuntu软件包的卸载和重新安装。一包一包

这将是相当耗时的,我不确定它是否会达到预期的结果

有没有更好的办法解决这个问题

以下是我在运行easy_install之前安装的软件包:

sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler gfortran libjpeg62 libfreeimage-dev libatlas-base-dev git python-dev python-pip libgoogle-glog-dev libbz2-dev libxml2-dev libxslt-dev libffi-dev libssl-dev libgflags-dev liblmdb-dev python-yaml python-numpy
$ sudo easy_install pillow
Searching for pillow
Reading https://pypi.python.org/simple/pillow/
Best match: Pillow 3.1.1
Downloading https://pypi.python.org/packages/source/P/Pillow/Pillow-3.1.1.zip#md5=3868f54fd164e65f95fbcb32f62940ae
Processing Pillow-3.1.1.zip
Writing /tmp/easy_install-Bvu_2f/Pillow-3.1.1/setup.cfg
Running Pillow-3.1.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Bvu_2f/Pillow-3.1.1/egg-dist-tmp-lMm5Tk
warning: no previously-included files found matching '.editorconfig'
Building using 4 processes
_imaging.c: In function ‘getink’:
_imaging.c:474:9: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int r, g, b, a;
         ^
libImaging/Resample.c:87:45: warning: always_inline function might not be inlinable [-Wattributes]
 static float __attribute__((always_inline)) i2f(int v) {
                                             ^
Building using 4 processes
Building using 4 processes
Building using 4 processes
--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version      Pillow 3.1.1
platform     linux2 2.7.6 (default, Jun 22 2015, 17:58:13)
             [GCC 4.8.2]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
*** OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
--- LIBTIFF support available
--- FREETYPE2 support available
*** LITTLECMS2 support not available
*** WEBP support not available
*** WEBPMUX support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.

Adding Pillow 3.1.1 to easy-install.pth file
Installing pildriver.py script to /usr/local/bin
Installing viewer.py script to /usr/local/bin
Installing gifmaker.py script to /usr/local/bin
Installing pilconvert.py script to /usr/local/bin
Installing pilfont.py script to /usr/local/bin
Installing pilfile.py script to /usr/local/bin
Installing createfontdatachunk.py script to /usr/local/bin
Installing explode.py script to /usr/local/bin
Installing pilprint.py script to /usr/local/bin
Installing player.py script to /usr/local/bin
Installing thresholder.py script to /usr/local/bin
Installing painter.py script to /usr/local/bin
Installing enhancer.py script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/Pillow-3.1.1-py2.7-linux-x86_64.egg
Processing dependencies for pillow
Finished processing dependencies for pillow
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 330, in _handle_workers
    debug('worker handler exiting')
TypeError: 'NoneType' object is not callable

Exception Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 357, in _handle_tasks
    debug('task handler got sentinel')
TypeError: 'NoneType' object is not callable

TypeError: TypeError("'NoneType' object does not support item deletion",) in <Finalize object, dead> ignored
ubuntu@ip-10-234-31-217:~/nvidia_installers/cuda$ 
以下是我从easy_install获得的初始异常:

sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler gfortran libjpeg62 libfreeimage-dev libatlas-base-dev git python-dev python-pip libgoogle-glog-dev libbz2-dev libxml2-dev libxslt-dev libffi-dev libssl-dev libgflags-dev liblmdb-dev python-yaml python-numpy
$ sudo easy_install pillow
Searching for pillow
Reading https://pypi.python.org/simple/pillow/
Best match: Pillow 3.1.1
Downloading https://pypi.python.org/packages/source/P/Pillow/Pillow-3.1.1.zip#md5=3868f54fd164e65f95fbcb32f62940ae
Processing Pillow-3.1.1.zip
Writing /tmp/easy_install-Bvu_2f/Pillow-3.1.1/setup.cfg
Running Pillow-3.1.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Bvu_2f/Pillow-3.1.1/egg-dist-tmp-lMm5Tk
warning: no previously-included files found matching '.editorconfig'
Building using 4 processes
_imaging.c: In function ‘getink’:
_imaging.c:474:9: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int r, g, b, a;
         ^
libImaging/Resample.c:87:45: warning: always_inline function might not be inlinable [-Wattributes]
 static float __attribute__((always_inline)) i2f(int v) {
                                             ^
Building using 4 processes
Building using 4 processes
Building using 4 processes
--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version      Pillow 3.1.1
platform     linux2 2.7.6 (default, Jun 22 2015, 17:58:13)
             [GCC 4.8.2]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
*** OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
--- LIBTIFF support available
--- FREETYPE2 support available
*** LITTLECMS2 support not available
*** WEBP support not available
*** WEBPMUX support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.

Adding Pillow 3.1.1 to easy-install.pth file
Installing pildriver.py script to /usr/local/bin
Installing viewer.py script to /usr/local/bin
Installing gifmaker.py script to /usr/local/bin
Installing pilconvert.py script to /usr/local/bin
Installing pilfont.py script to /usr/local/bin
Installing pilfile.py script to /usr/local/bin
Installing createfontdatachunk.py script to /usr/local/bin
Installing explode.py script to /usr/local/bin
Installing pilprint.py script to /usr/local/bin
Installing player.py script to /usr/local/bin
Installing thresholder.py script to /usr/local/bin
Installing painter.py script to /usr/local/bin
Installing enhancer.py script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/Pillow-3.1.1-py2.7-linux-x86_64.egg
Processing dependencies for pillow
Finished processing dependencies for pillow
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 330, in _handle_workers
    debug('worker handler exiting')
TypeError: 'NoneType' object is not callable

Exception Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 357, in _handle_tasks
    debug('task handler got sentinel')
TypeError: 'NoneType' object is not callable

TypeError: TypeError("'NoneType' object does not support item deletion",) in <Finalize object, dead> ignored
ubuntu@ip-10-234-31-217:~/nvidia_installers/cuda$ 
以下是我遵循的完整过程:

我知道apt get支持的pip版本非常旧。
我已尝试更新pip。
我收到“由操作系统拥有”错误。
我不确定如何偏离使用apt-get-here以及这样做的后果

$ pip install -U pip
Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-8.0.2-py2.py3-none-any.whl#md5=2056f553d5b593d3a970296f229c1b79
  Downloading pip-8.0.2-py2.py3-none-any.whl (1.2MB): 1.2MB downloaded
Installing collected packages: pip
  Found existing installation: pip 1.5.4
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, owned by OS
  Can't roll back pip; was not uninstalled
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files
    pycompile=self.pycompile,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber
    os.makedirs(destsubdir)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip-8.0.2.dist-info'

Storing debug log for failure in /home/ubuntu/.pip/pip.log

$ sudo pip install -U pip
Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-8.0.2-py2.py3-none-any.whl#md5=2056f553d5b593d3a970296f229c1b79
  Downloading pip-8.0.2-py2.py3-none-any.whl (1.2MB): 1.2MB downloaded
Installing collected packages: pip
  Found existing installation: pip 1.5.4
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, owned by OS
Successfully installed pip
Cleaning up...

$ pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
ubuntu@ip-10-234-31-217:~$ pip freeze
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/freeze.py", line 74, in run
    req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 286, in from_dist
    assert len(specs) == 1 and specs[0][0] == '=='
AssertionError

Storing debug log for failure in /home/ubuntu/.pip/pip.log
升级pip的另一种方法也失败:

$ sudo pip install --upgrade pip
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

$ pip freeze
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/freeze.py", line 74, in run
    req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 286, in from_dist
    assert len(specs) == 1 and specs[0][0] == '=='
AssertionError

Storing debug log for failure in /home/ubuntu/.pip/pip.log

$ ls -lF /home/ubuntu/.cache/pip/http
ls: cannot access /home/ubuntu/.cache/pip/http: No such file or directory
$ ls -lF /home/ubuntu/.cache
total 0
-rw-r--r-- 1 ubuntu ubuntu 0 Feb  6 00:39 motd.legal-displayed

为了在基于debian的linux发行版(包括ubuntu)上安装pip,我使用了来自
python setuptools
软件包的easy_install,获得了很好的效果。所以这通常看起来像:

sudo apt-get install python-setuptools
sudo easy_install pip
看起来您已经有了easy_安装。无论如何,在尝试以这种方式安装pip之前,您应该尽可能多地清理当前的设置。我将删除
python-pip
包,删除升级后的pip的任何其他痕迹,还将删除枕头模块的痕迹,因为当事情开始出错时,您正在安装枕头模块。可能是这样的:

sudo apt-get remove --purge python-pip
sudo rm -rf /usr/local/lib/python2.7/{dist,site}-packages/pip*
sudo rm -rf /usr/local/lib/python2.7/{dist,site}-packages/pillow*
最后,当您使用easy_install或pip安装除可导入python模块外还包含命令的东西时,该命令将被放入
/usr/local/bin
,因此您应该确保
/usr/local/bin
位于shell的
路径中。
pip
命令将在其中。(我只使用easy_install安装pip,然后使用pip安装任何其他python包。)

编辑:顺便说一下,“easy_install pillow的初始异常”不是异常,也不是错误。它显示了一些非致命的编译器警告,以及一些功能没有启用,但似乎已经起作用。可能是后来pip的行动给pip带来了问题


很久以后,编辑2:我有了一个“脑筋”,写了
/usr/local/lib
,在上面的最后一段原文中我的意思是
/usr/local/bin
。现已修复。

您是否查看了它提到的日志文件?是的。它完全复制打印到屏幕上的信息。没有其他信息。您是否更新了pip或在此处查看了任何解决方案:是。道歉。我应该提到这一点。我确实尝试过通过本页上的建议更新pip。更新以包含这些结果。嘿@AlexRyan,当你这样做时,你有什么
cat/home/ubuntu/.pip/pip.log