我最近在Windows 10 Home(64位)機器上安裝了「Anaconda3 for Windows v2.4.0」。導入matplotlib.pyplot時出錯(在Windows 10 Home 64位PC的Anaconda3上)
(我下載的是Windows 64位圖形安裝程序 「Anaconda3-2.4.0-Windows的x86_64.exe」 從https://www.continuum.io/downloads(392 MB)。)
在命令提示符窗口中,我做了暢達「試駕」,其中包括‘暢達更新暢達’,等等。最後,我看到以下內容:
C:\Users\Anshul\Downloads\Python>conda update conda
Fetching package metadata: ....
# All requested packages already installed.
# packages in environment at C:\Anaconda3:
#
conda 3.18.6 py35_0 defaults
C:\Users\Anshul\Downloads\Python>conda list matplotlib
# packages in environment at C:\Anaconda3:
#
matplotlib 1.5.0 np110py35_0 defaults
安裝似乎是成功的 - 例如:
C:\Users\Anshul\Downloads\Python>python
Python 3.5.0 |Anaconda 2.4.0 (64-bit)| (default, Nov 7 2015, 13:15:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World")
Hello World
>>> import os
>>> os.getcwd()
'C:\\Users\\Anshul\\Downloads\\Python'
>>> import matplotlib as mpl
>>> print(mpl.__version__)
1.5.0
>>>
注日在matplotlib上面導入罰款。不過,我得到一個錯誤信息,當我嘗試導入「matplotlib.pyplot」,如下圖所示:
>>> import matplotlib.pyplot as pp
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 1412, in <module>
fontManager = pickle_load(_fmcache)
File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 963, in pickle_load
with open(filename, 'rb') as fh:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Anshul\\.matplotlib\\fontList.py3k.cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:\Anaconda3\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Anaconda3\lib\site-packages\matplotlib\collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "C:\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 62, in <module>
import matplotlib.textpath as textpath
File "C:\Anaconda3\lib\site-packages\matplotlib\textpath.py", line 15, in <module>
import matplotlib.font_manager as font_manager
File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 1420, in <module>
_rebuild()
File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 1405, in _rebuild
fontManager = FontManager()
File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 1043, in __init__
self.ttffiles = findSystemFonts(paths) + findSystemFonts()
File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 312, in findSystemFonts
for f in win32InstalledFonts(fontdir):
File "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py", line 231, in win32InstalledFonts
direc = os.path.abspath(direc).lower()
File "C:\Anaconda3\lib\ntpath.py", line 535, in abspath
path = _getfullpathname(path)
ValueError: _getfullpathname: embedded null character
>>>
我打開「C:\ Anaconda3 \ LIB \站點包\ matplotlib \ font_manager.py」在文本編輯器,並試圖尋找錯誤的來源。我想,這就是事情會出錯:
>>> mpl.get_cachedir()
'C:\\Users\\Anshul\\.matplotlib'
>>> mpl.get_configdir()
'C:\\Users\\Anshul\\.matplotlib'
>>>
在Windows資源管理器,我看到了「C:\用戶\ Anshul.matplotlib」文件夾爲空,因此FileNotFoundError
爲「fontList.py3k.cache 「文件(我沒有看到」C:\ Anaconda3「目錄中的任何地方)。這似乎是安裝程序的問題(我認爲),但我不知道如何解決它。我會很感激任何幫助或指針。我在這個問題上已經嘗試過使用google搜索,最近發佈的是2013年的報告:fail to import matplotlib.pyplot #2320,它涉及到Windows 7 64位機器上WinPython-64bit-3.3.2.2的安裝。線程關閉與評論:「關閉已經固定在主」,但現在看來這個問題已經復出了,我希望有一個簡單的解決或解決方法)
感謝,
Anshul
我在Windows 7和香草python 3有同樣的問題,我不認爲Windows版本號是相關的。 – simonzack
只是調試了這一點,我認爲winreg.EnumValue是越野車,它有時會輸出沒有上限的字符串。 – simonzack