Windows上安装Python第三方库pycairo的解决办法
问题背景:
帮同学写了个绘制词云的程序,想打包成.exe文件发过去,结果打包的文件总是缺各种各样的包,几乎调试了一天...,说下爬坑经历。出现的问题有点多到记不清了,不过总的问题就是缺包,而且缺了个很重要的包cairo,绘制词云的时候会用到绘图方面的,所以需要这个包。
出现问题:
如果缺包的话,在打包过程中可能会提示出如下报错:
fatal error C1083:Cannot open include file: 'cairo.h': No such file or directory
或者
ModuleNotFoundError: No module named 'cairo'
或者
OSError:no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e
既然报错,那就开始装包,如果直接装cairo包会失败,应该是没这个库,在Python上是pycairo库。
直接pip装pycairo包也会安装失败
报错
Running setup.py install for pycairo ... error
ERROR: Failed building wheel for pycairo
在查过一些资料后发现,pycairo需要编译才能正常安装,这就比较头疼,因为没有编译的环境。
后来这个问题就被搁置在了一边。。。
在接触完Python的基础语法后,经老师讲解才知道了一个专门维护Python需要编译包才能安装的网站,上面是已经编译后的第三方包,下载后直接安装就成。
具体的可以在这篇找到:
Python部分第三方库简要介绍及近期Python入门学习笔记
下载后,安装pycairo就能够成功安装了。
安装包从上面网站下当然可以,不过速度嘛,确实不敢恭维,1M的包都能下好几次,索性我将下载成功的包放到了CSDN我的资源那里,有需要的可以去免费下载。记得对应Python的版本和位号,cp后面是Python版本号。
目前不知道CSDN抽什么风,3.7版本的pycairo一直传不上去(明明还没有传过),如果实在下不下来,可以试一试下3.8版本的,不过我不知道会不会有兼容错误。
当然,现在生成的.exe还是不能正常运行...,估计还得调试,下面贴一些返回信息,与本文关联不大,有兴趣的可以看看。
112 INFO: PyInstaller: 3.6
113 INFO: Python: 3.8.1
113 INFO: Platform: Windows-7-6.1.7601-SP1
115 INFO: wrote E:\Python\File\DrawWordCloudVersion1.0.spec
128 INFO: UPX is not available.
140 INFO: Extending PYTHONPATH with paths
['E:\\Python\\File', 'E:\\Python\\File']
141 INFO: checking Analysis
141 INFO: Building Analysis because Analysis-00.toc is non existent
142 INFO: Initializing module dependency graph...
146 INFO: Caching module graph hooks...
154 INFO: Analyzing base_library.zip ...
4146 INFO: Processing pre-find module path hook distutils
4147 INFO: distutils: retargeting to non-venv dir 'e:\\python\\python3.8.1\\lib'
6294 INFO: Caching module dependency graph...
6443 INFO: running Analysis Analysis-00.toc
6471 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by e:\python\python3.8.1\python.exe
6875 INFO: Analyzing E:\Python\File\DrawWordCloudVersion1.0.py
7123 INFO: Processing pre-find module path hook site
7124 INFO: site: retargeting to fake-dir 'e:\\python\\python3.8.1\\lib\\site-packages\\PyInstaller\\fake-modules'
8109 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
15851 INFO: Processing pre-safe import module hook six.moves
18713 INFO: Processing module hooks...
18713 INFO: Loading module hook "hook-distutils.py"...
18716 INFO: Loading module hook "hook-encodings.py"...
18852 INFO: Loading module hook "hook-lib2to3.py"...
18859 INFO: Loading module hook "hook-matplotlib.backends.py"...
19885 INFO: Matplotlib backend "GTK3Agg": ignored
The GTK3 backends require PyGObject
20516 INFO: Matplotlib backend "GTK3Cairo": ignored
The GTK3 backends require PyGObject
20982 INFO: Matplotlib backend "MacOSX": ignored
cannot import name '_macosx' from 'matplotlib.backends' (e:\python\python3.8.1\lib\site-packages\matplotlib\backends\__init__.py)
21452 INFO: Matplotlib backend "nbAgg": ignored
No module named 'IPython'
22016 INFO: Matplotlib backend "Qt4Agg": added
22582 INFO: Matplotlib backend "Qt4Cairo": added
23145 INFO: Matplotlib backend "Qt5Agg": added
23694 INFO: Matplotlib backend "Qt5Cairo": added
24350 INFO: Matplotlib backend "TkAgg": added
25008 INFO: Matplotlib backend "TkCairo": added
25675 INFO: Matplotlib backend "WebAgg": added
26291 INFO: Matplotlib backend "WX": ignored
No module named 'wx'
26766 INFO: Matplotlib backend "WXAgg": ignored
No module named 'wx'
27230 INFO: Matplotlib backend "WXCairo": ignored
No module named 'wx'
27723 INFO: Matplotlib backend "agg": added
28204 INFO: Matplotlib backend "cairo": added
28853 INFO: Matplotlib backend "pdf": added
29498 INFO: Matplotlib backend "pgf": added
30036 INFO: Matplotlib backend "ps": added
30518 INFO: Matplotlib backend "svg": added
31127 INFO: Matplotlib backend "template": added
31740 INFO: Loading module hook "hook-matplotlib.py"...
32160 INFO: Loading module hook "hook-numpy.core.py"...
32307 INFO: Loading module hook "hook-numpy.py"...
32309 INFO: Loading module hook "hook-PIL.Image.py"...
32710 INFO: Loading module hook "hook-PIL.py"...
32713 INFO: Excluding import 'tkinter'
32715 INFO: Removing import of tkinter from module PIL.ImageTk
32716 INFO: Import to be excluded not found: 'FixTk'
32716 INFO: Excluding import 'PyQt4'
32720 INFO: Excluding import 'PySide'
32724 INFO: Excluding import 'PyQt5'
32730 INFO: Removing import of PyQt5.QtCore from module PIL.ImageQt
32731 INFO: Removing import of PyQt5.QtGui from module PIL.ImageQt
32733 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
32735 INFO: Excluding import 'tkinter'
32737 INFO: Import to be excluded not found: 'FixTk'
32737 INFO: Loading module hook "hook-pkg_resources.py"...
33318 INFO: Processing pre-safe import module hook win32com
33447 INFO: Excluding import '__main__'
33449 INFO: Removing import of __main__ from module pkg_resources
33450 INFO: Loading module hook "hook-pycparser.py"...
33451 INFO: Loading module hook "hook-pydoc.py"...
33453 INFO: Loading module hook "hook-PyQt5.py"...
33636 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
33736 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
34017 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
34322 INFO: Loading module hook "hook-pythoncom.py"...
34754 INFO: Loading module hook "hook-pywintypes.py"...
35206 INFO: Loading module hook "hook-scipy.py"...
35212 INFO: Loading module hook "hook-setuptools.py"...
35932 INFO: Loading module hook "hook-sysconfig.py"...
35933 INFO: Loading module hook "hook-win32com.py"...
36310 INFO: Loading module hook "hook-xml.dom.domreg.py"...
36311 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
36312 INFO: Loading module hook "hook-xml.py"...
36313 INFO: Loading module hook "hook-_tkinter.py"...
36569 INFO: checking Tree
36569 INFO: Building Tree because Tree-00.toc is non existent
36570 INFO: Building Tree Tree-00.toc
36662 INFO: checking Tree
36662 INFO: Building Tree because Tree-01.toc is non existent
36662 INFO: Building Tree Tree-01.toc
36730 INFO: Looking for ctypes DLLs
36829 INFO: Analyzing run-time hooks ...
36837 INFO: Including run-time hook 'pyi_rth__tkinter.py'
36840 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
36844 INFO: Including run-time hook 'pyi_rth_pkgres.py'
36846 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
36852 INFO: Including run-time hook 'pyi_rth_pyqt5.py'
36854 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
36857 INFO: Including run-time hook 'pyi_rth_mpldata.py'
36885 INFO: Looking for dynamic libraries
38980 INFO: Looking for eggs
38981 INFO: Using Python library e:\python\python3.8.1\python38.dll
38981 INFO: Found binding redirects:
[]
38995 INFO: Warnings written to E:\Python\File\build\DrawWordCloudVersion1.0\warn-DrawWordCloudVersion1.0.txt
39192 INFO: Graph cross-reference written to E:\Python\File\build\DrawWordCloudVersion1.0\xref-DrawWordCloudVersion1.0.html
39261 INFO: checking PYZ
39261 INFO: Building PYZ because PYZ-00.toc is non existent
39262 INFO: Building PYZ (ZlibArchive) E:\Python\File\build\DrawWordCloudVersion1.0\PYZ-00.pyz
41557 INFO: Building PYZ (ZlibArchive) E:\Python\File\build\DrawWordCloudVersion1.0\PYZ-00.pyz completed successfully.
41599 INFO: checking PKG
41600 INFO: Building PKG because PKG-00.toc is non existent
41600 INFO: Building PKG (CArchive) PKG-00.pkg
75198 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
75238 INFO: Bootloader e:\python\python3.8.1\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
75239 INFO: checking EXE
75240 INFO: Building EXE because EXE-00.toc is non existent
75240 INFO: Building EXE from EXE-00.toc
75241 INFO: Appending archive to EXE E:\Python\File\dist\DrawWordCloudVersion1.0.exe
75351 INFO: Building EXE from EXE-00.toc completed successfully.
本文地址:https://blog.csdn.net/qq_45053285/article/details/107082463
上一篇: 奥飞动漫推三款机器人并参股图灵
下一篇: CSS颜色表示