Python 由于pycairo 1.20,无法导入matplotlib

Python 由于pycairo 1.20,无法导入matplotlib,python,matplotlib,pip,setuptools,Python,Matplotlib,Pip,Setuptools,我在导入python3脚本的matplotlibrary时遇到问题 我的系统: CentOS Linux 7(核心) 内核3.10.0-1062.9.1.el7.x86_64 Python 3.6.8 最小复制: python3 >>>from matplotlib import pyplot as plt 设置: python3 -m venv tester source tester/bin/activate pip install matplotlib pip list

我在导入python3脚本的matplotlibrary时遇到问题

我的系统: CentOS Linux 7(核心) 内核3.10.0-1062.9.1.el7.x86_64 Python 3.6.8

最小复制:

python3
>>>from matplotlib import pyplot as plt
设置:

python3 -m venv tester
source tester/bin/activate
pip install matplotlib
pip list
给出:

Package         Version
--------------- ---------
certifi         2020.6.20
cycler          0.10.0
kiwisolver      1.2.0
matplotlib      3.3.2
numpy           1.19.2
Pillow          8.0.1
pip             18.1
pyparsing       2.4.7
python-dateutil 2.8.1
setuptools      40.6.2
six             1.15.0
Traceback (most recent call last):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 15, in <module>
    import cairo
ModuleNotFoundError: No module named 'cairo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 21, in <module>
    import cairocffi as cairo
ModuleNotFoundError: No module named 'cairocffi'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2336, in <module>
    switch_backend(rcParams["backend"])
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 276, in switch_backend
    class backend_mod(matplotlib.backend_bases._Backend):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 277, in backend_mod
    locals().update(vars(importlib.import_module(backend_name)))
  File "/apps/shared/taifun/x86_64/apps/DATAPROCESSING/python/3.6.8/system/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 25, in <module>
    "is installed") from err
ImportError: cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
Collecting pycairo
  Downloading <internal-package-server>/5a10cb7f9ae0d/pycairo-1.20.0.tar.gz (344kB)
    100% |████████████████████████████████| 348kB 3.7MB/s
  Installing build dependencies ... done
Installing collected packages: pycairo
  Running setup.py install for pycairo ... done
Successfully installed pycairo-1.20.0
现在谈谈实际复制:

python3
>>>from matplotlib import pyplot as plt
给出:

Package         Version
--------------- ---------
certifi         2020.6.20
cycler          0.10.0
kiwisolver      1.2.0
matplotlib      3.3.2
numpy           1.19.2
Pillow          8.0.1
pip             18.1
pyparsing       2.4.7
python-dateutil 2.8.1
setuptools      40.6.2
six             1.15.0
Traceback (most recent call last):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 15, in <module>
    import cairo
ModuleNotFoundError: No module named 'cairo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 21, in <module>
    import cairocffi as cairo
ModuleNotFoundError: No module named 'cairocffi'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2336, in <module>
    switch_backend(rcParams["backend"])
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 276, in switch_backend
    class backend_mod(matplotlib.backend_bases._Backend):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 277, in backend_mod
    locals().update(vars(importlib.import_module(backend_name)))
  File "/apps/shared/taifun/x86_64/apps/DATAPROCESSING/python/3.6.8/system/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 25, in <module>
    "is installed") from err
ImportError: cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
Collecting pycairo
  Downloading <internal-package-server>/5a10cb7f9ae0d/pycairo-1.20.0.tar.gz (344kB)
    100% |████████████████████████████████| 348kB 3.7MB/s
  Installing build dependencies ... done
Installing collected packages: pycairo
  Running setup.py install for pycairo ... done
Successfully installed pycairo-1.20.0
给出:

Package         Version
--------------- ---------
certifi         2020.6.20
cycler          0.10.0
kiwisolver      1.2.0
matplotlib      3.3.2
numpy           1.19.2
Pillow          8.0.1
pip             18.1
pyparsing       2.4.7
python-dateutil 2.8.1
setuptools      40.6.2
six             1.15.0
Traceback (most recent call last):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 15, in <module>
    import cairo
ModuleNotFoundError: No module named 'cairo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 21, in <module>
    import cairocffi as cairo
ModuleNotFoundError: No module named 'cairocffi'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2336, in <module>
    switch_backend(rcParams["backend"])
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 276, in switch_backend
    class backend_mod(matplotlib.backend_bases._Backend):
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 277, in backend_mod
    locals().update(vars(importlib.import_module(backend_name)))
  File "/apps/shared/taifun/x86_64/apps/DATAPROCESSING/python/3.6.8/system/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 25, in <module>
    "is installed") from err
ImportError: cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
Collecting pycairo
  Downloading <internal-package-server>/5a10cb7f9ae0d/pycairo-1.20.0.tar.gz (344kB)
    100% |████████████████████████████████| 348kB 3.7MB/s
  Installing build dependencies ... done
Installing collected packages: pycairo
  Running setup.py install for pycairo ... done
Successfully installed pycairo-1.20.0
看起来还可以:

Package         Version
--------------- ---------
...
pycairo         1.20.0
...
新尝试:

python3
>>>from matplotlib import pyplot as plt
不,同样的错误:

...
ImportError: cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
现在,将版本调整为1.11可以起作用:

pip uninstall pycairo
pip install pycairo==1.11
python3
>>> from matplotlib import pyplot as plt
>>>
万岁

但是为什么pycairo1.20不能在这里工作呢?1.11->1.20不应该是一个突破性的改变,其他人应该早点发现这个问题。我可能会错过什么?或者我真的应该在matplotlib开一张罚单,这样他们就可以调整他们的请求了。名单


提前谢谢。

好的,我设法解决了这个问题。需要采取若干步骤:

  • 从pycairo切换到cairocffi(根据CForce99建议)
  • 更新pip和setuptools(通过进入gitlab-cy.yml),旧版本(40.x)与Cairocf的.tar.gz有问题
  • 设置公司内部pypi镜像(导出请求\u CA\u捆绑包)的证书路径

如果安装最新版本的cairocffi“pip安装cairocffi”,会发生什么情况