Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to import matplotlib into IPython notebook #5919

Closed
plantgustaf opened this issue Jan 26, 2016 · 9 comments
Closed

Error when trying to import matplotlib into IPython notebook #5919

plantgustaf opened this issue Jan 26, 2016 · 9 comments

Comments

@plantgustaf
Copy link

Hi, I'm getting the following error:

import matplotlib
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-82be63b7783c> in <module>()
----> 1 import matplotlib

/Users/Gustaf/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in <module>()
   1129 
   1130 # this is the instance used by the matplotlib classes
-> 1131 rcParams = rc_params()
   1132 
   1133 if rcParams['examples.directory']:

/Users/Gustaf/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in rc_params(fail_on_error)
    973         return ret
    974 
--> 975     return rc_params_from_file(fname, fail_on_error)
    976 
    977 

/Users/Gustaf/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in rc_params_from_file(fname, fail_on_error, use_default_template)
   1098         parameters specified in the file. (Useful for updating dicts.)
   1099     """
-> 1100     config_from_file = _rc_params_in_file(fname, fail_on_error)
   1101 
   1102     if not use_default_template:

/Users/Gustaf/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in _rc_params_in_file(fname, fail_on_error)
   1016     cnt = 0
   1017     rc_temp = {}
-> 1018     with _open_file_or_url(fname) as fd:
   1019         try:
   1020             for line in fd:

/Users/Gustaf/anaconda/lib/python3.5/contextlib.py in __enter__(self)
     57     def __enter__(self):
     58         try:
---> 59             return next(self.gen)
     60         except StopIteration:
     61             raise RuntimeError("generator didn't yield") from None

/Users/Gustaf/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in _open_file_or_url(fname)
    998     else:
    999         fname = os.path.expanduser(fname)
-> 1000         encoding = locale.getdefaultlocale()[1]
   1001         if encoding is None:
   1002             encoding = "utf-8"

/Users/Gustaf/anaconda/lib/python3.5/locale.py in getdefaultlocale(envvars)
    557     else:
    558         localename = 'C'
--> 559     return _parse_localename(localename)
    560 
    561 

/Users/Gustaf/anaconda/lib/python3.5/locale.py in _parse_localename(localename)
    485     elif code == 'C':
    486         return None, None
--> 487     raise ValueError('unknown locale: %s' % localename)
    488 
    489 def _build_localename(localetuple):

ValueError: unknown locale: UTF-8

Any ideas how to fix this? Thanks!

@jenshnielsen
Copy link
Member

I think this is a duplicate of #5420 which is really a OSX bug.

The work around is to set LANG and possiblly export LC_ALL to valid values such as some thing like the following:

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

@jenshnielsen
Copy link
Member

I updated the formatting of your output to make it more readable

@plantgustaf
Copy link
Author

Thanks so much! That worked!

@plantgustaf
Copy link
Author

Do I have to enter this every time I start the IPython notebook? Because it seems like that I have to do this.

@jenshnielsen
Copy link
Member

The best solution is to add it to your shell customisation so it's run every time you start a shell. You are probably running bash so it should be either .bash_profile or .bashrc in your home folder

@jenshnielsen
Copy link
Member

Could I get you to try the following to review #5931 which is a probably better work around for this issue.
In the notebook where importing matploltlib fails what does do

import locale
locale.getpreferredencoding(do_setlocale=False)

see #5931 which may be the right fix for this.

@plantgustaf
Copy link
Author

Ok the fix for me:
Enter in Terminal: touch ~/.bash_profile; open ~/.bash_profile
Add

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

to the end of the file.
Save & Quit.

@samanemt
Copy link

Hi, I'm getting the following error:
ValueError Traceback (most recent call last)
in ()
----> 1 mlp.fit(X_train,y_train)

C:\Users\samaneh\Anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py in fit(self, X, y)
616 self : returns a trained MLP model.
617 """
--> 618 return self._fit(X, y, incremental=False)
619
620 @Property

C:\Users\samaneh\Anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py in _fit(self, X, y, incremental)
328 hidden_layer_sizes)
329
--> 330 X, y = self._validate_input(X, y, incremental)
331 n_samples, n_features = X.shape
332

C:\Users\samaneh\Anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py in _validate_input(self, X, y, incremental)
906 if not incremental:
907 self._label_binarizer = LabelBinarizer()
--> 908 self.label_binarizer.fit(y)
909 self.classes
= self.label_binarizer.classes
910 else:

C:\Users\samaneh\Anaconda3\lib\site-packages\sklearn\preprocessing\label.py in fit(self, y)
296 self.y_type_ = type_of_target(y)
297 if 'multioutput' in self.y_type_:
--> 298 raise ValueError("Multioutput target data is not supported with "
299 "label binarization")
300 if _num_samples(y) == 0:

ValueError: Multioutput target data is not supported with label binarization
Any ideas how to fix this? Thanks!

@efiring
Copy link
Member

efiring commented Nov 30, 2017

@samanemt, the traceback shows that the error is coming from scikit-learn, not from matplotlib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants