Cannot import Imread from Pylab - python

import numpy as np
import pandas as pd
import cv2
from matplotlib import pyplot as plt
from pylab import imread
from skimage.color import rgb2gray
from PIL import Image
from skimage import feature
I reinstalled Windows 10, so I had to reinstall Anaconda and Jupyter also.
I usually use these import statements, however, now I'm getting an error:
ImportError: cannot import name 'imread' from 'pylab'
(C:\Users\DELL\Anaconda3\lib\site-packages\pylab__init__.py)
Do you have any suggestions? I have installed Pylab, PIL and Matplotlib already.

Try to add:
from matplotlib.pyplot import imread
in stead of:
from pylab import imread

Related

Importing library in python (Pycharm)

These are the libraries within the script asked for import
## Import libraries
import numpy
import dill
import pandas
import peakutils
import os
import scipy
from scipy.signal import butter, lfilter, freqz
import smooth
from peakutils.plot import plot
from matplotlib import pyplot
I did several however, not for butter,lfilter, freqz, os,
what I have to do?
I imported several libraries but not all.

My result is not getting saved as an ouput in jupyter notebook yet

import matplotlib.pyplot as plt
import seaborn as sns
from skimage.io import imread, imshow
import cv2
%matplotlib inline
import plotly.offline as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.tools as tls
from subprocess import check_output
from subprocess import call
print(os.listdir("C:\\Users\\admin\\Downloads\\input\\train"))
print(check_output(["ls", "../input"]).decode("utf8"))
The output is not getting saved.
Following are the errors
Following is the error

Python in vscode: Import errors do not show up in terminal

I'm writing python scripts in vscode and recently I've been having a problem related to imports.
Lines of code above imports work and their output is displayed in the terminal:
print("hellow")
import matplotlib.pyplot as plt
import numpy as np
#from scipy.special import erfc
from scipy.linalg import solve
> hellow
Lines of code below the imports are not executed, but no errors are displayed in the terminal!
import matplotlib.pyplot as plt
import numpy as np
#from scipy.special import erfc
from scipy.linalg import solve
print("hellow")
>
I'm guessing there is something wrong with my vscode settings, but why are no errors showing up in the terminal?
Thanks for your help.

How to get matplotlib working in Python3 on OS X?

I am trying to do Google's deep learning course on Udemy. For assignment one I need to verify that the following modules are working on my machine, but can't get matplotlib.pyplot working. The python code I must get to compile is the following:
# These are all the modules we'll be using later. Make sure you can import them
# before proceeding further.
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import tarfile
from IPython.display import display, Image
from scipy import ndimage
from sklearn.linear_model import LogisticRegression
from six.moves.urllib.request import urlretrieve
from six.moves import cPickle as pickle
# Config the matplotlib backend as plotting inline in IPython
%matplotlib inline
When I compile and run this like so:
python3.6 nn_assignment_1.py
I get the following error:
Traceback (most recent call last):
File "nn_assignment_1.py", line 9, in <module>
from IPython import display, Image
ImportError: cannot import name 'Image'
Any ideas how to get matplotlib working for python 3 here? I have been banging my head against the keyboard for hours trying to figure this out.

Why suddenly matplotlib import doesn't work without any error signaling?

This piece of code:
from matplotlib import pyplot as plt
always worked fine until now.
When i run every files with this piece of code, they are runned up to this code line and then the execution is stopped without error signaling.
It works as if the file ended on that line.
My matplotlib version is 1.2.0, and numpy 1.6.2.
How can i solve it?
Reinstalling the module?
UPDATE:
from __future__ import division
import os
import glob
import scipy
import numpy as np
import pymorph as pm
#import pylab as plb
#import math
import matplotlib
print("before matplot")
from matplotlib import pyplot as plt
print("after matplot")
import cv2
import mahotas as mh
from skimage import morphology
from math import sqrt
import copy
#... the others code's lines (1700 lines of code) are runned only if
#"from matplotlib import pyplot as plt" is commented
output:
>>> ================================ RESTART ================================
>>>
before matplot
>>> ================================ RESTART ================================
>>>
UPDATE 2:
import matplotlib.pyplot as plt; plt.figure(); plt.show()
from python Shell works and open a grey windows with command bar below
<matplotlib.figure.Figure object at 0x03741B70>
I was having the same issue. It looks like if you remove the .pyc file from the directory it works just fine. Check this answer out for more info https://stackoverflow.com/a/14132653/1373468

Categories

Resources