【问题标题】:Installing functools gives me AttributeError 'module' object has no attribute 'compose'安装 functools 给我 AttributeError 'module' object has no attribute 'compose'
【发布时间】:2013-07-26 03:48:26
【问题描述】:

我在新系统上安装了 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

【问题讨论】:

  • 这个旧问题的标题中出现错误消息的新原因是:compose() 不再属于functools 模块。您可以使用def compose(f,g): return lambda x: f(g(x))

标签: python python-2.7 pip


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    在 Windows 上找到了解决方案。

    1. 删除 site-packages 文件夹中对 functools 的任何引用。
    2. easy_install -U pip==7.1.2

    【讨论】:

      【解决方案3】:

      Python2.7自带functools模块。

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

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

      【讨论】:

        猜你喜欢
        • 2015-09-26
        • 1970-01-01
        • 2017-05-10
        • 2014-12-20
        • 1970-01-01
        • 2022-12-01
        • 2022-12-01
        • 1970-01-01
        • 2014-09-29
        相关资源
        最近更新 更多