Matplotlib有许多可选的依赖项,它们提供了可选功能。已启用的功能在安装时显示,但如何在安装后再次显示?
答案 0 :(得分:1)
安装matplotlib时看到的可选依赖项输出是由setupext.py中定义的一组环境测试程序生成的。这些列表按照显示的顺序列在setup.py:
中mpl_packages = [
'Building Matplotlib',
setupext.Matplotlib(),
setupext.Python(),
setupext.Platform(),
'Required dependencies and extensions',
setupext.Numpy(),
setupext.Dateutil(),
setupext.FuncTools32(),
setupext.Pytz(),
setupext.Cycler(),
setupext.Tornado(),
setupext.Pyparsing(),
setupext.LibAgg(),
setupext.FreeType(),
setupext.FT2Font(),
setupext.Png(),
setupext.Qhull(),
setupext.Image(),
setupext.TTConv(),
setupext.Path(),
setupext.ContourLegacy(),
setupext.Contour(),
setupext.Delaunay(),
setupext.QhullWrap(),
setupext.Tri(),
setupext.Externals(),
'Optional subpackages',
setupext.SampleData(),
setupext.Toolkits(),
setupext.Tests(),
setupext.Toolkits_Tests(),
'Optional backend extensions',
# These backends are listed in order of preference, the first
# being the most preferred. The first one that looks like it will
# work will be selected as the default backend.
setupext.BackendMacOSX(),
setupext.BackendQt5(),
setupext.BackendQt4(),
setupext.BackendGtk3Agg(),
setupext.BackendGtk3Cairo(),
setupext.BackendGtkAgg(),
setupext.BackendTkAgg(),
setupext.BackendWxAgg(),
setupext.BackendGtk(),
setupext.BackendAgg(),
setupext.BackendCairo(),
setupext.Windowing(),
'Optional LaTeX dependencies',
setupext.DviPng(),
setupext.Ghostscript(),
setupext.LaTeX(),
setupext.PdfToPs(),
'Optional package data',
setupext.Dlls(),
]
实际检查在同一个文件中进一步显示:
for package in mpl_packages:
if isinstance(package, str):
print_raw('')
print_raw(package.upper())
else:
try:
result = package.check()
if result is not None:
message = 'yes [%s]' % result
print_status(package.name, message)
except setupext.CheckFailed as e:
msg = str(e).strip()
if len(msg):
print_status(package.name, 'no [%s]' % msg)
else:
print_status(package.name, 'no')
if not package.optional:
required_failed.append(package)
else:
good_packages.append(package)
if isinstance(package, setupext.OptionalBackendPackage):
if default_backend is None:
default_backend = package.name
不幸的是,由于Python安装的工作方式,一旦安装了matplotlib,这些文件都不可用。但是,如果您有matplotlib源(或repo)的副本,则可以运行检查而不执行matplotlib的完全重新安装,如下所示。
首先将matplotlib源文件夹添加到sys.path,然后将目录更改为该文件夹(versioneer.py
需要执行此第二步)。
import os, sys
PATH = r'\your\path\to\matplotlib'
sys.path.append(PATH)
import setupext # setupext.py contains the dependency definitions
os.chdir(PATH)
接下来,定义要测试的包/依赖项列表。
mpl_packages = [
'Building Matplotlib',
setupext.Matplotlib(),
setupext.Python(),
setupext.Platform(),
'Required dependencies and extensions',
setupext.Numpy(),
setupext.Dateutil(),
setupext.FuncTools32(),
setupext.Pytz(),
setupext.Cycler(),
setupext.Tornado(),
setupext.Pyparsing(),
setupext.LibAgg(),
setupext.FreeType(),
setupext.FT2Font(),
setupext.Png(),
setupext.Qhull(),
setupext.Image(),
setupext.TTConv(),
setupext.Path(),
setupext.ContourLegacy(),
setupext.Contour(),
setupext.Delaunay(),
setupext.QhullWrap(),
setupext.Tri(),
setupext.Externals(),
'Optional subpackages',
setupext.SampleData(),
setupext.Toolkits(),
setupext.Tests(),
setupext.Toolkits_Tests(),
'Optional backend extensions',
# These backends are listed in order of preference, the first
# being the most preferred. The first one that looks like it will
# work will be selected as the default backend.
setupext.BackendMacOSX(),
setupext.BackendQt5(),
setupext.BackendQt4(),
setupext.BackendGtk3Agg(),
setupext.BackendGtk3Cairo(),
setupext.BackendGtkAgg(),
setupext.BackendTkAgg(),
setupext.BackendWxAgg(),
setupext.BackendGtk(),
setupext.BackendAgg(),
setupext.BackendCairo(),
setupext.Windowing(),
'Optional LaTeX dependencies',
setupext.DviPng(),
setupext.Ghostscript(),
setupext.LaTeX(),
setupext.PdfToPs(),
'Optional package data',
setupext.Dlls(),
]
最后,迭代可选包并测试它们。这个减少的测试循环输出每个依赖性检查的结果,而不用担心存储它们等等。
for package in mpl_packages:
if isinstance(package, str):
print('')
print(package.upper())
else:
try:
result = package.check()
if result is not None:
message = 'yes [%s]' % result
print(package.name, message)
except setupext.CheckFailed as e:
msg = str(e).strip()
if len(msg):
print(package.name, 'no [%s]' % msg)
else:
print(package.name, 'no')
在我当前的系统上,这给了我以下输出:
BUILDING MATPLOTLIB
matplotlib yes [1.5.0+319.g781605a]
python yes [3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)]]
platform yes [win32]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy yes [version 1.10.4]
dateutil yes [using dateutil version 2.5.2]
functools32 yes [Not required]
pytz yes [using pytz version 2016.3]
cycler yes [using cycler version 0.10.0]
tornado yes [using tornado version 4.3]
pyparsing yes [using pyparsing version 2.0.3]
libagg yes [pkg-config information for 'libagg' could not be found. Using local copy.]
freetype no [The C/C++ header for freetype (ft2build.h) could not be found. You may need to install the development package.]
png no [The C/C++ header for png (png.h) could not be found. You may need to install the development package.]
qhull yes [pkg-config information for 'qhull' could not be found. Using local copy.]
OPTIONAL SUBPACKAGES
sample_data yes [installing]
toolkits yes [installing]
tests yes [using nose version 1.3.7 / using unittest.mock]
toolkits_tests yes [using nose version 1.3.7 / using unittest.mock]
OPTIONAL BACKEND EXTENSIONS
macosx no [Mac OS-X only]
qt5agg no [PyQt5 not found]
qt4agg yes [installing, Qt: 4.8.7, PyQt: 4.8.7; PySide not found]
gtk3agg no [Requires pygobject to be installed.]
gtk3cairo no [Requires cairocffi or pycairo to be installed.]
gtkagg no [Requires pygtk]
tkagg no [The C/C++ header for Tk (tk.h) could not be found. You may need to install the development package.]
wxagg no [requires wxPython]
gtk no [Requires pygtk]
agg yes [installing]
cairo no [cairocffi or pycairo not found]
windowing yes [installing, installing]
OPTIONAL LATEX DEPENDENCIES
dvipng yes [version 1.12]
ghostscript no
latex yes [version MiKTeX 2.9]
pdftops no
OPTIONAL PACKAGE DATA
dlls no [skipping due to configuration]