12

我在新系统上安装了 Ubuntu 12.04 64 位,无法安装 functools。我已经安装了多次,但不记得收到此错误,并且无法通过 Google 找到任何解决方案。我需要做什么?

(myvenv)bobs@myvenv:~$ pip install functools
Downloading/unpacking functools
  Downloading functools-0.5.tar.gz
  Running setup.py egg_info for package functools
    Traceback (most recent call last):
      File "<string>", line 3, in <module>
      File "/home/bobs/.virtualenvs/myvenv/local/lib/python2.7/site-packages/setuptools/__init__.py", line 2, in <module>
        from setuptools.extension import Extension, Library
      File "/home/bobs/.virtualenvs/myvenv/local/lib/python2.7/site-packages/setuptools/extension.py", line 5, in <module>
        from setuptools.dist import _get_unpatched
      File "/home/bobs/.virtualenvs/myvenv/local/lib/python2.7/site-packages/setuptools/dist.py", line 10, in <module>
        from setuptools.compat import numeric_types, basestring
      File "/home/bobs/.virtualenvs/myvenv/local/lib/python2.7/site-packages/setuptools/compat.py", line 17, in <module>
        import httplib
      File "/usr/lib/python2.7/httplib.py", line 71, in <module>
        import socket
      File "/usr/lib/python2.7/socket.py", line 49, in <module>
        from functools import partial
      File "functools.py", line 72, in <module>
        globals()['c_%s' % x] = globals()[x] = getattr(_functools, x)
    AttributeError: 'module' object has no attribute 'compose'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 3, in <module>

  File "/home/bobs/.virtualenvs/myvenv/local/lib/python2.7/site-packages/setuptools/__init__.py", line 2, in <module>

    from setuptools.extension import Extension, Library

  File "/home/bobs/.virtualenvs/myvenv/local/lib/python2.7/site-packages/setuptools/extension.py", line 5, in <module>

    from setuptools.dist import _get_unpatched

  File "/home/bobs/.virtualenvs/myvenv/local/lib/python2.7/site-packages/setuptools/dist.py", line 10, in <module>

    from setuptools.compat import numeric_types, basestring

  File "/home/bobs/.virtualenvs/myvenv/local/lib/python2.7/site-packages/setuptools/compat.py", line 17, in <module>

    import httplib

  File "/usr/lib/python2.7/httplib.py", line 71, in <module>

    import socket

  File "/usr/lib/python2.7/socket.py", line 49, in <module>

    from functools import partial

  File "functools.py", line 72, in <module>

    globals()['c_%s' % x] = globals()[x] = getattr(_functools, x)

AttributeError: 'module' object has no attribute 'compose'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/bobs/.virtualenvs/myvenv/build/functools
Storing complete log in /home/bobs/.pip/pip.log
4

3 回答 3

11

Python2.7 自带了 functools 模块。

如果你想获得 Python3.2 引入的 lru-cache 装饰器,你可以安装 functools32。

编辑:我实际上检查了这个。当我尝试使用 Python2.7 安装 functools 时,我遇到了同样的错误。只需import functools照常进行。

于 2013-07-26T04:27:38.920 回答
1

确保它是 python 版本 2.x 中的 functools32。在 3.x 中,这些工具是内置的。

于 2019-06-11T11:35:32.610 回答
0

在windows上找到了解决方案。

  1. 删除 site-packages 文件夹中对 functools 的任何引用。
  2. easy_install -U pip==7.1.2
于 2016-04-19T02:01:46.153 回答