jupyter unable to show inline graphics - matplotlib

i installed jupyter via pip with python34 on my rhel6 system (via scl). i can run the notebook fine, however, i am unable to get any of the magics to work and i am also unable to plot anything (ie no graphics).
an example notebook:
import seaborn as sns
import matplotlib
print("%s"%(matplotlib.matplotlib_fname(),))
print("%s"%(matplotlib.get_backend(),))
import matplotlib.pyplot as plt
/opt/pyspark/lib/python3.4/site-packages/matplotlib/mpl-data/matplotlibrc
TkAgg
trying to plot something:
import numpy as np
import pandas as pd
import random
df = pd.DataFrame()
df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)
(df.head())
sns.lmplot('x','y', data=df, fit_reg=False)
Name: org.apache.toree.interpreter.broker.BrokerException
Message: Traceback (most recent call last):
File "/tmp/kernel-PySpark-fc7b8287-6d11-43eb-9569-be81655a0bcf/pyspark_runner.py", line 134, in <module>
eval(compiled_code)
File "<string>", line 1, in <module>
File "/opt/pyspark/lib/python3.4/site-packages/seaborn/linearmodels.py", line 548, in lmplot
legend_out=legend_out)
File "/opt/pyspark/lib/python3.4/site-packages/seaborn/axisgrid.py", line 307, in __init__
fig, axes = plt.subplots(nrow, ncol, **kwargs)
File "/opt/pyspark/lib/python3.4/site-packages/matplotlib/pyplot.py", line 1185, in subplots
fig = figure(**fig_kw)
File "/opt/pyspark/lib/python3.4/site-packages/matplotlib/pyplot.py", line 535, in figure
**kwargs)
File "/opt/pyspark/lib/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 84, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/opt/pyspark/lib/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 92, in new_figure_manager_given_figure
window = Tk.Tk()
File "/opt/rh/rh-python34/root/usr/lib64/python3.4/tkinter/__init__.py", line 1851, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
StackTrace: org.apache.toree.interpreter.broker.BrokerState$$anonfun$markFailure$1.apply(BrokerState.scala:140)
org.apache.toree.interpreter.broker.BrokerState$$anonfun$markFailure$1.apply(BrokerState.scala:140)
scala.Option.foreach(Option.scala:236)
org.apache.toree.interpreter.broker.BrokerState.markFailure(BrokerState.scala:139)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:381)
py4j.Gateway.invoke(Gateway.java:259)
py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
py4j.commands.CallCommand.execute(CallCommand.java:79)
py4j.GatewayConnection.run(GatewayConnection.java:209)
java.lang.Thread.run(Thread.java:745)
note i ssh into the linux box from my mac with a local port forward to view the jupyter notebooks.
attempting to run magics:
%matplotlib inline
Name: Error parsing magics!
Message: Magics [matplotlib] do not exist!
StackTrace:
list of yum installs:
- rh-python34
- python-virtualenv
- python-setuptools
- python-pip
- rh-python34-python-tkinter
list of pip installs:
- pandas
- matplotlib
- scipy
- numpy
- seaborn
- jupyter

Related

this commands fig, axs = plt.subplots(2, 2) show error UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

I am running the following command in spyder,
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2)
Traceback (most recent call last):
File "/home/hh/.local/lib/python3.8/site-packages/matplotlib_inline/backend_inline.py", line 41, in show
display(
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/IPython/core/display.py", line 327, in display
publish_display_data(data=format_dict, metadata=md_dict, **kwargs)
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/IPython/core/display.py", line 119, in publish_display_data
display_pub.publish(
File "/home/hh/.local/lib/python3.8/site-packages/ipykernel/zmqshell.py", line 138, in publish
self.session.send(
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/jupyter_client/session.py", line 830, in send
to_send = self.serialize(msg, ident)
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/jupyter_client/session.py", line 704, in serialize
content = self.pack(content)
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/jupyter_client/session.py", line 95, in json_packer
return jsonapi.dumps(
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/zmq/utils/jsonapi.py", line 40, in dumps
s = jsonmod.dumps(o, **kwargs)
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/simplejson/init.py", line 398, in dumps
return cls(
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/simplejson/encoder.py", line 296, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/simplejson/encoder.py", line 378, in iterencode
return _iterencode(o, 0)
File "/home/hh/anaconda3/envs/gee/lib/python3.8/site-packages/simplejson/encoder.py", line 44, in encode_basestring
s = str(s, 'utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
Got the same error if I run the same code in jupyter lab. However, if I run the command on terminal, the fig, ax = plt.subplots() works fine.
This only happens recently and I didn't have this issue before. Checked online material, but didn't find a solution. appreciate if only can provide any insights. thanks.
I had the same problem running plain jupyter and within vscode.
Try updating the jupyter installation incl. required libraries. In my case
pip3 install --upgrade jupyter_client pyzmq
fixed the problem.

Tensorflow Extended(TFX) code runs fine on Google Colab, but throws error when running on a local machine

I have the following code using Tensorflow Extended(TFX)
from tfx.utils.dsl_utils import csv_input
from tfx.components.example_gen.csv_example_gen.component import CsvExampleGen
examples = csv_input(os.path.join(base_dir, 'data/simple'))
example_gen = CsvExampleGen(input=examples);
When I execute this code on Google Colab, it works fine. However, when I run this
Traceback (most recent call last):
File "tfx_sample.py", line 4, in
from tfx.components.example_gen.csv_example_gen.component import CsvExampleGen
File "/Users/sv/tfx_env/lib/python3.7/site-packages/tfx/components/init.py", line 20, in
from tfx.components.bulk_inferrer.component import BulkInferrer
File "/Users/sv/tfx_env/lib/python3.7/site-packages/tfx/components/bulk_inferrer/component.py", line 24, in
from tfx.components.base import base_component
File "/Users/sv/tfx_env/lib/python3.7/site-packages/tfx/components/base/base_component.py", line 28, in
from tfx.components.base import base_driver
File "/Users/sv/tfx_env/lib/python3.7/site-packages/tfx/components/base/base_driver.py", line 28, in
from tfx.orchestration import metadata
File "/Users/sv/tfx_env/lib/python3.7/site-packages/tfx/orchestration/metadata.py", line 36, in
from ml_metadata.metadata_store import metadata_store
File "/usr/local/lib/python3.7/site-packages/ml_metadata/metadata_store/init.py", line 15, in
from ml_metadata.metadata_store.metadata_store import MetadataStore
File "/usr/local/lib/python3.7/site-packages/ml_metadata/metadata_store/metadata_store.py", line 32, in
from ml_metadata.metadata_store import pywrap_tf_metadata_store_serialized as metadata_store_serialized
File "/usr/local/lib/python3.7/site-packages/ml_metadata/metadata_store/pywrap_tf_metadata_store_serialized.py", line 28, in
_pywrap_tf_metadata_store_serialized = swig_import_helper()
File "/usr/local/lib/python3.7/site-packages/ml_metadata/metadata_store/pywrap_tf_metadata_store_serialized.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tf_metadata_store_serialized', fp, pathname, description)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: dlopen(/usr/local/lib/python3.7/site-packages/ml_metadata/metadata_store/_pywrap_tf_metadata_store_serialized.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /usr/local/lib/python3.7/site-packages/ml_metadata/metadata_store/_pywrap_tf_metadata_store_serialized.so (which was built for Mac OS X 10.15)
Expected in: /usr/lib/libSystem.B.dylib
in /usr/local/lib/python3.7/site-packages/ml_metadata/metadata_store/_pywrap_tf_metadata_store_serialized.so
Here's the version details of installed packages
apache-beam 2.20.0
tensorboard 1.15.0
tensorboard-plugin-wit 1.6.0.post3
tensorflow 1.15.0
tensorflow-data-validation 0.23.0.dev0
tensorflow-estimator 1.15.1
tensorflow-metadata 0.22.0
tensorflow-model-analysis 0.21.5
tensorflow-serving-api 2.1.0
tensorflow-transform 0.22.0
tfx 0.21.4
tfx-bsl 0.22.0
Please use the latest version(0.29.0) available for tfx.
Working code to resolve the issue :-
import os
import tfx
from tfx.utils.dsl_utils import external_input
from tfx.components.example_gen.csv_example_gen.component import CsvExampleGen
import tempfile
import urllib
_data_root = tempfile.mkdtemp(prefix='tfx-data')
DATA_PATH = 'https://raw.githubusercontent.com/tensorflow/tfx/master/tfx/examples/chicago_taxi_pipeline/data/simple/data.csv'
_data_filepath = os.path.join(_data_root, "data.csv")
urllib.request.urlretrieve(DATA_PATH, _data_filepath)
example_gen = CsvExampleGen(input_base=(_data_filepath))

Receive error when I run an executable created after py2exe conversion

After running my setup.py file and attempt to run the newly created .exe file I receive an error log that says:
Traceback (most recent call last):
File "Healthy_temp.py", line 7, in <module>
File "pandas\__init__.pyc", line 42, in <module>
File "pandas\core\api.pyc", line 26, in <module>
File "pandas\core\groupby\__init__.pyc", line 1, in <module>
File "pandas\core\groupby\groupby.pyc", line 37, in <module>
File "pandas\core\frame.pyc", line 100, in <module>
File "pandas\core\series.pyc", line 4390, in <module>
File "pandas\core\generic.pyc", line 10138, in _add_series_or_dataframe_operations
File "pandas\core\window.pyc", line 14, in <module>
File "pandas\_libs\window.pyc", line 12, in <module>
File "pandas\_libs\window.pyc", line 10, in __load
File "pandas\_libs\skiplist.pxd", line 31, in initpandas._libs.window
ImportError: No module named skiplist
My setup.py file is here:
from distutils.core import setup
import py2exe
import matplotlib
from PyQt4 import QtCore, QtGui
from AboutDialog import Ui_Dialog
from matplotlibwidget import MatplotlibWidget
import sys
from os import walk
from os import getcwd
import pandas
import numpy
from glob import glob
from datetime import datetime
from math import isnan
import sip
# setup(windows=['Healthy_temp.py'])
setup(options={'py2exe': {'bundle_files': 3, 'compressed': True}}, windows=[
'Healthy_temp.py'], zipfile=None,
data_files=matplotlib.get_py2exe_datafiles())
What can I do to correct this problem?
Add 'pandas._libs.skiplist' to the "includes" option list.

ImportError: No module named 'matplotlib._cntr'

When I run
#!/usr/bin/env python
import matplotlib
import matplotlib.pyplot as plt
I get following error
Traceback (most recent call last):
File "/home/wayne/alphaWorldsPython/code/mapTest.py", line 12, in <module>
import matplotlib.pyplot as plt
File "/home/wayne/matplotlib/pyplot.py", line 32, in <module>
import matplotlib.colorbar
File "/home/wayne/matplotlib/colorbar.py", line 36, in <module>
import matplotlib.contour as contour
File "/home/wayne/matplotlib/contour.py", line 14, in <module>
import matplotlib._cntr as _cntr
ImportError: No module named 'matplotlib._cntr'
When I look in matplotlib indeed ._cntr is not present.
I have tried reinstalling and updating. No change.
._cntr was a private module and it was removed from matplotlib. you can install this to still have the ._cntr in your matplotlib
https://github.com/matplotlib/legacycontour

cannot import matplotlib.pylab with matplotlib installed

I understand that there have been several questions asked on this topic, however, I didn't find them able to solve my problem.
I installed matplotlib on the maching under /python-path/site-packages, both library and python are 64bits,
so I could import matplotlib no problem, but when I tried to import matplotlib.pylab or pylab, it gives me the following error
Traceback (most recent call last):
File "shownet.py", line 40, in <module>
import matplotlib.pylab
File "/usr/lib64/python2.6/site-packages/matplotlib/pylab.py", line 247, in <module>
from matplotlib.pyplot import *
File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 78, in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py", line 8, in <module>
import gtk; gdk = gtk.gdk
File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
_init()
File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
_gtk.init_check()
Would anyone know why this is so?
Also this is on linux, and I built it using setup.py