Matplotlib编译错误:TypeError:unorderable类型:str()< INT()

时间:2014-11-19 18:55:49

标签: python python-3.x matplotlib

我正在尝试使用python setup.py build在python 3.4上添加matplotlib-1.4.2。根据它在python 3.4上支持的文档。我收到以下错误消息:

IMPORTANT WARNING:
    pkg-config is not installed.
    matplotlib may not be able to find some of its dependencies
============================================================================
Edit setup.cfg to change the build options

BUILDING MATPLOTLIB
            matplotlib: yes [1.4.2]
                python: yes [3.4.0 (default, Nov 17 2014, 15:12:48)  [GCC
                        4.1.2 20080704 (Red Hat 4.1.2-48)]]
              platform: yes [linux]

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [version 1.9.1]
                   six: yes [using six version 1.8.0]
              dateutil: yes [using dateutil version 2.2]
                  pytz: yes [using pytz version 2014.9]
               tornado: yes [using tornado version 4.0.2]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                 pycxx: yes [Official versions of PyCXX are not compatible
                        with matplotlib on Python 3.x, since they lack
                        support for the buffer object.  Using local copy]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
Traceback (most recent call last):
  File "setup.py", line 155, in <module>
    result = package.check()
  File "/users/tools/downloads/matplotlib-1.4.2/setupext.py", line 962, in check
    min_version='2.3', version=version)
  File "/users/tools/downloads/matplotlib-1.4.2/setupext.py", line 446, in _check_for_pkg_config
    if (not is_min_version(version, min_version)):
  File "/users/tools/downloads/matplotlib-1.4.2/setupext.py", line 174, in is_min_version
    return found_version >= expected_version
  File "/users/tools/python-3.4.0/lib/python3.4/distutils/version.py", line 76, in __ge__
    c = self._cmp(other)
  File "/users/tools/python-3.4.0/lib/python3.4/distutils/version.py", line 342, in _cmp
    if self.version < other.version:
TypeError: unorderable types: str() < int()

请帮助解决它。

1 个答案:

答案 0 :(得分:52)

我遇到了类似的错误,并且能够通过安装可选的依赖项来修复它。具体来说,在我的情况下,有一个&#39; bug&#39;因为在distutils / version.py:343中对字符串和整数类型进行隐式比较,松散的版本号比较可以在Python 3中触发错误,这是从Matplotlib的setup.py中调用的。如果需要,请参阅Issue 14894以获取更多详细信息。

由于未安装可选的依赖项,因此版本号检查返回一个字符串(&#34;无法识别版本。&#34;)当然,无法将其与数字进行比较版本,它抛出你看到的同样的例外。

sudo apt-get install libfreetype6-dev
pip install matplotlib

安装了libfreetype(一个可选的依赖项),distutil的LooseVersion看到了一个版本号并正确输入了比较。 Matplotlib此后安装得很好。