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

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?

Related

ModuleNotFoundError: No module named 'seaborn' in spdyer

I recently installed spyder on my macbook (M1). I am getting module not found error when I tried to load seaborn.
Pl note
I am able to load the seaborn in jupyter notebook
Whey I change the python interpreter to the the one jupyter notebook is using (i.e. miniforge), I get following error
/Users/akbarboghani/miniforge3/bin/python: Error while finding module specification for 'spyder_kernels.console' (ModuleNotFoundError: No module named 'spyder_kernels')
Is there any setting I have missed? How do I resolve this
I tried changing preferences and restarted the spyder application. Checked for solution, did not find any.

TensorCirucit c.draw() NameError

I want to plot a circuit build with TensorCircuit using the draw method.
I am working on Google Colab and have pip installed qiskit.
Yet i get NameError: name 'QuantumCircuit' is not defined.
I have also tried from qiskit import QuantumCircuit but still i get the same error.
Executing the code on another JuypterHub works.
pip install qiskit
pip install pylatexenc
import numpy as np
from qiskit import *
Once you are done with above code you have to restart your runtime so that installed library come into force into your colab environment.
For restarting runtime:
Click on Runtime
Select Restart runtime
Select Run all
This help you to rectify your problem.

Cannot find module PIL in Python

I am using:
Thonny Version 3.2.1
Python Version 3.7.0
PIP Version 19.2.3
Pillow Version 6.1.0
I am trying to import an image into my program and show it on the screen with the below code:
I get the error:
ModuleNotFoundError: No module named 'PIL'
backend.py, line 276
I believe the problem isn't my code, but instead an issue with the module Pillow not being found by Python?
Can anyone please help with a fix? I can clarify any info needed.
Additionally, I am new to Python and so go easy on me :-) Apologies if any of my terminology is incorrect.
I have tried:
1\ Removing PIL as per the install warning from Pillow (PIL Fork) install info. It was not present on my system. I did this through CMD.
2\ I always access CMD as the administrator.
3\ Updating all program versions above through CMD.
4\ Info I’ve found shows the above versions are compatible.
5\ Using the code help('modules') to show available modules, it does not show 'PIL' or 'Image', but does show 'pip'.
6\ Checked many forums for other fixes.
from PIL import Image
im = Image.open("JC.png")
im.show()

Send help in the form of someone who knows python well

I am currently well versed in java, but I am trying to get into python. I know the basics, but am struggling with package use and implementation into source code.
I have successfully installed both numpy and Pillow (or PIL):
Click here for cmd telling me both packages have been installed
When I typed import numpy into cmd running python, it worked no problem, but now I've tried to open IDLE and import it there, and written source code trying to import it and utalise parts of the numpy lib but it always gives me a ModuleNotFoundError
python idle shell import vs. cmd import
My folder layout is a little wacky:
C:
..Users
....B
......ForImagingProject
........PYTHON
..........(python standard subfolders)
..........Lib
............site-packages
..............numpy and PIL and pip here
Any and all help would be appreciated
Thanks ~ B
EDIT: I messed up and my IDLE shortcut was running idle.pyw instead of idle.bat. Everything working smoothly now.
Check your IDLE's python executable. Is it the same one as in your cmd prompt?
The easiest way to check is to run this:
import sys
print(sys.path)
Look for something like
'PATH_TO_PYTHON/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7'or
'PATH_TO_PYTHON/Frameworks/Python.framework/Versions/2.7/lib/python2.7'
Make sure this is the same in both the IDLE and in cmd.
The reason the shell I was working in was unable to recognize the module was because my IDLE shortcut was mapped to idle.pyw instead of idle.bat. Everything running smoothly now

import matplotlib.pyplot crashes on jupyter notebook

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