import matplotlib.pyplot crashes on jupyter notebook - matplotlib

I have a jupyter notebook running on a remote cluster to which I have set up an ssh tunnel. Everything was working fine till today. Now everytime I do :
import matplotlib # This works
%matplotlib inline # This causes kernel to restart
import matplotlib.pyplot # This also causes the kernel to restart
Running a standalone ipython interpreter and doing :
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot ## Leads to Core dumped : Segementation Fault
Running the same on a python interpreter works fine.
Jupyter version : 4.1.1
Python version : 2.7.7
Any help would be much appreciated.
Thank You

Often, this kind of error seems to be related to the backend. Have you tried any other backends? Do these result in the same error? Like this we could narrow down the source of the error.
(I don't have a remote cluster, so I can not reproduce it.)
You can find available backends as described here.

I perhaps have the same problem but on my local machine. I got into jupyter3-qtconsole 4.2.1 with Python 3.4.5 and IPython 5.0.0. and enter
`%matplotlib
Using matplotlib backend: Qt4Agg`
the error message (shortened):
File "/usr/lib64/python3.4/site-packages/tornado/ioloop.py", line 603, in _run_callback
ret = callback()
and finally
from IPython.core.interactiveshell import NoOpContext as context
ImportError: cannot import name 'NoOpContext'
Same thing happens in a notebook but in a straightforward IPython terminal, everything runs OK
Hope this is helpful to someone

Related

ModuleNotFoundError: using Spyder

6 Hours into trying to fix this i gave up.
Im just trying to import basic moduls that are installed on my MAC, i can run bs4, pandas etc etc on sublime, jupyter etc except SPYDER. The console outputs the following
File "<ipython-input-1-50b2309bcaa6>", line 1, in <module>
import bs4
ModuleNotFoundError: No module named 'bs4'
Things i have tried.
I changed the Nano file on mac so that Python = 'python3' and pip = 'pip3': Didn't work.
Changing the IPython console settings to Run a module: Worked for the module Request but the the other modules still fail (bs4,pandas,etcetc)
Restarting my computer 100 times: Didn't work
Googeling the shit out of it: Didn't work
Uppercutting the MAC: Didn't work

How to fix matplotlib.pyplot problem in installed matplotlib in python

I am new in python and last month I have installed matplotlib module in my python and using that I have also done some codes successfully. But now suddenly I don't know why my matlpotlib module is not working. When I write "import matplotlib.pyplot as plt" it shows the error "ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package" and the codes that was done before are also not working and showing the same error."import matplotlib" statement works properly in command prompt and IDLE. What am I suppose to do to solve this problem?

pandas not works for django?

I saw the first rocket.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world.")
'Hello, world.' it's ok!
also 'python manage.py migrate' ok.
But when I import pandas...
(import only and no use.)
from django.http import HttpResponse
import pandas as pd
def index(request):
return HttpResponse("Hello, world.")
Browser thinks forever.
How can I fix this issue?
my environment
OS: CentOS Linux release 7.7.1908 (Core)
Pandas: 0.19.2
Apache: 2.4.6 (CentOS)
Django: 2.1
Browser: Google Chrome 76.0.3809.132
# python --version
Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
simply, Anaconda is older?
Please let me know if there is any missing information.
Progress after that. Tried "Panda" update.
#Conda installs panda
I was able to clear the browser thinking during the import error.
I will re-install Newest Anaconda.
(_mysql_exceptions.OperationalError) (2006, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)") (Background on this error at: sqlalche.me/e/e3q8)
Currently, if you don't use django, you can execute SQL from py file to MySQL.
The situation has improved. It hasn't been resolved yet, but the error has changed this morning. I will challenge again when the work is over.
Settled! I think anaconda was old. Speaking of which, it took about two years to build a VPS, and anaconda was the version at that time.

ModuleNotFoundError: No module named 'pandas.io' for json_normalize

Please read carefully. In my Python script I have the following:
import json
import pandas
from pandas.io.json import json_normalize
and it returns the following error:
from pandas.io.json import json_normalize ModuleNotFoundError: No
module named 'pandas.io'; 'pandas' is not a package
My steps:
I have uninstalled and installed Pandas
I have upgraded pip and pandas
I have installed io (pip install -U pandas.io)
I have installed data_reader and replaced the pandas.io.json part with that: from pandas_datareader import json_normalize
I have tried every solution I saw on stackoverflow and github and nothing worked. The only one I have not tried is installing Anaconda but it should work with what I tried before. Do you think it is a Windows setting things I must change?
PS: My Python version is 3.7.4
Try:
Go to ...\Lib\site-packages\pytrends on your local disk and open file request.py
Change
from pandas.io.json._normalize import nested_to_record
to
from pandas.io.json.normalize import nested_to_record
I had the same error, but it helped me.
also change
from pandas.io.json.normalize
to
from pandas.io.json._normalize
The cause of the problem was the fact that the python file had the name pandas. The filename was pandas.py. After renaming it, the code worked normally without errors.
i had same problem and i solve it b uninstalling extra python versions install on my windows.now i have only one python installed by anaconda,and everything is working perfectly

Cannot import Keras on Pycharm

I tried to code on Pycharm, but when I use from keras import backend as K it throws an import error like "cannot import name backend". But I can do it on terminal.
How can I fix this?
error
on terminal
Are you sure your PyCharm sees the same Python environment as what you are using in Terminal?
See if this possibly works for you:
use tensorflow on pyCharm
I got the same problem:
Check here:Pycharm cannot find installed packages: keras
After adding new package to project interpreter, you need to quit Pycharm and restart it again.
Use
from tensorflow.python.keras import backend as K
instead.