Error on import matplotlib.pyplot (on Anaconda3 for Windows 10 Home 64-bit PC)

Hello,

I just installed "Anaconda3 for Windows v2.4.0" on my Windows 10 Home (64
bit) machine.

(Downloaded the Windows 64-bit Graphical Installer
"Anaconda3-2.4.0-Windows-x86_64.exe" (392 MB) from
https://www.continuum.io/downloads)

In a Command Prompt window, I did the conda "Test Drive", including "conda
update conda", etc, and in the end see the following:

The installation seems to have been successful:

However, I get an error message when I try to import "matplotlib.pyplot" as
below (note that matplotlib appears to be imported fine):

I opened "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py" in a
text editor and tried to look for the source of the error. I think this is
where things are going wrong:

But I'm at a loss as to why this is happening, and how to rectify it.
Please help.

Thanks,
Anshul

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151129/bbd51300/attachment.html>

Sigh, this is mostly a py3k/Windows issue, I think (a long-standing one).
We have been seeing some strange issues in Windows where users who have
certain Unicode characters in their username and something unusual about
their filesystem (I don't recall what it is, specifically). Those
characters end up messing up various parts of the standard library and
return incorrect results or raise exceptions like these.

I do remember that there was a discussion thread about a year or two ago
that really went into detail about why this was happening, and that there
was nothing we could do from within the library. Perhaps someone remembers
what thread that was?

Ben Root

···

On Sun, Nov 29, 2015 at 4:26 PM, anshul6 via Matplotlib-users < matplotlib-users at python.org> wrote:

Hello,

I just installed "Anaconda3 for Windows v2.4.0" on my Windows 10 Home (64
bit) machine.

(Downloaded the Windows 64-bit Graphical Installer
"Anaconda3-2.4.0-Windows-x86_64.exe" (392 MB) from
https://www.continuum.io/downloads)

In a Command Prompt window, I did the conda "Test Drive", including "conda
update conda", etc, and in the end see the following:

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

The installation seems to have been successful:

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
>>>

However, I get an error message when I try to import "matplotlib.pyplot"
as below (note that matplotlib appears to be imported fine):

>>> 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
>>>

I opened "C:\Anaconda3\lib\site-packages\matplotlib\font_manager.py" in a
text editor and tried to look for the source of the error. I think this is
where things are going wrong:

>>> mpl.get_cachedir()
'C:\\Users\\Anshul\\.matplotlib'
>>> mpl.get_configdir()
'C:\\Users\\Anshul\\.matplotlib'
>>>

But I'm at a loss as to why this is happening, and how to rectify it.
Please help.

Thanks,
Anshul
------------------------------
View this message in context: Error on import matplotlib.pyplot (on
Anaconda3 for Windows 10 Home 64-bit PC)
<http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477.html&gt;
Sent from the matplotlib - users mailing list archive
<http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html&gt; at
Nabble.com.

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151130/68d47e76/attachment-0001.html&gt;

Thank you Ben for the reply.

Perhaps you are referring to this one reported back in 2013: fail to import
matplotlib.pyplot #2320
<https://github.com/matplotlib/matplotlib/issues/2320/> ? It involved a
WinPython-64bit-3.3.2.2 installation on a Windows 7 64 bit machine.

The thread was closed with the comment: "Closing. Already fixed in master.",
but I have to confess, I didn't understand the discussion that led to this
conclusion.

Is there a simple set of instructions on what I need to do to fix this
installation issue?

Thank you,
Anshul

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477p46481.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151130/a60ed339/attachment.html>

No, not that one. This issue has to do with getting the home directory of
the user, I think, so it was a problem with os.path.expanduser(), IIRC.

···

On Mon, Nov 30, 2015 at 3:38 PM, anshul6 via Matplotlib-users < matplotlib-users at python.org> wrote:

Thank you Ben for the reply.

Perhaps you are referring to this one reported back in 2013: fail to
import matplotlib.pyplot #2320
<https://github.com/matplotlib/matplotlib/issues/2320/&gt;? It involved a
WinPython-64bit-3.3.2.2 installation on a Windows 7 64 bit machine.

The thread was closed with the comment: "Closing. Already fixed in
master.", but I have to confess, I didn't understand the discussion that
led to this conclusion.

Is there a simple set of instructions on what I need to do to fix this
installation issue?

Thank you,
Anshul
------------------------------
View this message in context: Re: Error on import matplotlib.pyplot (on
Anaconda3 for Windows 10 Home 64-bit PC)
<http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477p46481.html&gt;

Sent from the matplotlib - users mailing list archive
<http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html&gt; at
Nabble.com.

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151130/2680b6c1/attachment.html&gt;

BTW, the error is not limited to just "matplotlib.pyplot". I get a similar
error when importing the "seaborn" library. These are the two packages that
I know of so far. Hope there is one fix for all such issues.

Below is my seaborn installation procedure, and the subsequent error message
triggered on import.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477p46484.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

In case anyone else is facing this issue, "simonzack" wrote a simple patch
<http://stackoverflow.com/a/34007642/5622032> on StackOverflow that fixed
the problem for me!

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477p46504.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

To defend against linkrot, here is that user's answer:

This is a bug in python, not matplotlib.

The issue is that winreg.EnumValue is not cutting string values at their
length properly for some reason, and strings will include null characters
which os.path.abspath is not able to process.

The registry entry where this happens is at SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Fonts. Despite this not being matplotlib's fault we can
still temporarily patch it so that it ends the string at '\0'. In
font_manager.py, patch line 310 in the win32InstalledFonts() function to:

key, direc, any = winreg.EnumValue( local, j)if not is_string_like(direc):
    continueif not os.path.dirname(direc):
    direc = os.path.join(directory, direc)
direc = direc.split('\0', 1)[0]

···

On Tue, Dec 1, 2015 at 3:29 PM, anshul6 via Matplotlib-users < matplotlib-users at python.org> wrote:

In case anyone else is facing this issue, "simonzack" wrote a simple patch
<python 3.x - Error on import matplotlib.pyplot (on Anaconda3 for Windows 10 Home 64-bit PC) - Stack Overflow; on StackOverflow that
fixed
the problem for me!

--
View this message in context:
http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477p46504.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151201/9123aa3c/attachment-0001.html&gt;

Just FYI: I reported the problem on "Python bug tracker" and their Windows
experts are trying to debug it: bugs.python.org/issue25778

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477p46520.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Thanks for the heads up. Looks like we will need to include the patch on
our end for now as well.

···

On Fri, Dec 4, 2015, 08:23 anshul6 via Matplotlib-users < matplotlib-users at python.org> wrote:

Just FYI: I reported the problem on "Python bug tracker" and their Windows
experts are trying to debug it: bugs.python.org/issue25778

--
View this message in context:
http://matplotlib.1069221.n5.nabble.com/Error-on-import-matplotlib-pyplot-on-Anaconda3-for-Windows-10-Home-64-bit-PC-tp46477p46520.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151204/e95bfa21/attachment.html&gt;