首页 > 解决方案 > Python TensorFlow

问题描述

我在安装 Tensorflow 模块时遇到问题,我已经完成了研究,但我无法在线找到解决方案。我只运行 tensorflow 示例代码。

import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile

from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image

# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops

if StrictVersion(tf.__version__) < StrictVersion('1.9.0'):
  raise ImportError('Please upgrade your TensorFlow installation to v1.9.* or later!')

这是输出:

FileNotFoundError                         Traceback (most recent call last)
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in <module>()
   1352         try:
-> 1353             fontManager = json_load(_fmcache)
   1354             if (not hasattr(fontManager, '_version') or

c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in json_load(filename)
    887     """
--> 888     with open(filename, 'r') as fh:
    889         return json.load(fh, object_hook=_json_decode)

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Mestre\\.matplotlib\\fontlist-v300.json'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-1e9eee4e6961> in <module>()
     10 from collections import defaultdict
     11 from io import StringIO
---> 12 from matplotlib import pyplot as plt
     13 from PIL import Image
     14 

c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\pyplot.py in <module>()
     30 from cycler import cycler
     31 import matplotlib
---> 32 import matplotlib.colorbar
     33 import matplotlib.image
     34 from matplotlib import rcsetup, style

c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\colorbar.py in <module>()
     30 import matplotlib.collections as collections
     31 import matplotlib.colors as colors
---> 32 import matplotlib.contour as contour
     33 import matplotlib.cm as cm
     34 import matplotlib.gridspec as gridspec

c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\contour.py in <module>()
     16 import matplotlib.colors as mcolors
     17 import matplotlib.collections as mcoll
---> 18 import matplotlib.font_manager as font_manager
     19 import matplotlib.text as text
     20 import matplotlib.cbook as cbook

c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in <module>()
   1361             raise
   1362         except Exception:
-> 1363             _rebuild()
   1364     else:
   1365         _rebuild()

c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in _rebuild()
   1342         global fontManager
   1343 
-> 1344         fontManager = FontManager()
   1345 
   1346         if _fmcache:

c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in __init__(self, size, weight)
    976         self.defaultFont = {}
    977 
--> 978         ttffiles = findSystemFonts(paths) + findSystemFonts()
    979         self.defaultFont['ttf'] = next(
    980             (fname for fname in ttffiles

c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in findSystemFonts(fontpaths, fontext)
    262             fontpaths = [win32FontDirectory()]
    263             # now get all installed fonts directly...
--> 264             fontfiles.update(win32InstalledFonts(fontext=fontext))
    265         else:
    266             fontpaths = X11FontDirectories

TypeError: 'NoneType' object is not iterable

matplotlib 似乎有问题,但我已经安装了该模块,并编译了 protoc 文件,这是我第三次尝试安装 tensorflow 但没有成功。感谢所有会回复的小伙子再次感谢,宝拉

标签: pythonpython-3.xtensorflow

解决方案


这是 matplotlib 中的一个错误。在lib/matplotlib/font_manager.py您需要将win32InstalledFonts功能更改为return []而不是return None.

记录在这里: https ://github.com/matplotlib/matplotlib/pull/12174/files


推荐阅读