Successfully installed SciPy, but "from scipy.misc import imread" gives ImportError: cannot import name 'imread' - tensorflow

I have successfully installed scipy, numpy, and pillow, however I get error as below
ImportError: cannot import name 'imread'

Are you following the same steps?
import scipy.misc
img = scipy.misc.imread('my_image_path')
# To verify image is read properly.
import matplotlib.pyplot as plt
print(img.shape)
plt.imshow(img)
plt.show()

imread and imsave are deprecated in scipy.misc
Use imageio.imread instead after import imageio.
For saving -
Use imageio.imsave instead or use imageio.write
For resizing use skimage.transform.resize instead after import skimage

Related

Getting an error : "OptionError: 'You can only set the value of existing options'" in python

I am getting an error:
"OptionError: 'You can only set the value of existing options'"
after using the below code, please can someone help?
### Data Analaysis
import numpy as np
import pandas as pd
### Data Visualization
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objs as go
import plotly.express as px
from plotly.subplots import make_subplots
from scipy.interpolate import make_interp_spline, BSpline
%matplotlib inline
import warnings
warnings.simplefilter(action='ignore', category=Warning)
pd.set_option('display.max_columns', None)
pd.options.plotting.backend = "plotly"
The option error "you can only set the value of existing options" are coming because of your last line of script
pd.options.plotting.backend = "plotly"
where you are trying to update your pandas backend plotting method.
Please update your pandas and plotly packages. Because it only works with pandas version>=0.25 and plotly version>=4.8.
So update both the packages, restart your kernel, if you are working on Jupyter notebook. For upgrading the packages
pip install -U pandas
pip install -U plotly

Can't call matplotlib attributes v3.2.2

Whenever I try to run the following code I get an error message
import matplotlib
import pandas as pd
import _pickle as pickle
import numpy as np
print(matplotlib.version)
AttributeError: module 'matplotlib' has no attribute 'version'
I get the same error if i try this: matplotlib.style.use('bmh')
I'm using PyCharm
The errors are stating those attributes do not exist. It is not a problem of the installation.
To get the version:
print(matplotlib.__version__)
Regarding the style:
You do not "apply" that in matplotlib. You may want to use the module pyplot:
import matplotlib.pyplot as plt
plt.style.use("bmh")

Why there is giving, name 'pd ' is not defined error?

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
dataset = pd.read_csv('homeprice.csv')
print(dataset)
Output
NameError Traceback (most recent call
last) in
----> 1 dataset = pd.read_csv('homeprice.csv')
2 print(dataset)
NameError: name 'pd' is not defined
You mention that you are using a Jupiter notebook so you may have two code cells:
First is with the imports:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
And the second is with the functionality:
dataset = pd.read_csv('homeprice.csv')
print(dataset)
In Jupiter notebooks you may run each cell separately. If this is what you do, you should remember the run the first cell before you execute the second one for the first time. This would make sure the right stuff is imported in the current context for you second cell.
!pip install tensorflow-gpu==2.2.0.0rc2
import tensorflow as tf
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
Or
Just go with the latest TensorFlow version in the Colab

ImportError: cannot import name '_path'

i must install matplotlib on a offline PC with python 3.5....to run some scripts. I copy the lib to the Right path on the offline PC....all other lib like reportlab are running. But if i trie to write something with matplotlib.pyplot as plt i got the Error Message "ImportError:cannot Import 'path'".
a the first step i
Import matplotlib
matplotlib.use('aggs')
Import matplotlib.pyplot as plt
the biggest Problem i cant download something on this offline pc.
So i am rly new to write some codes with python so pls dont jugde me guys =)
So the frist step was delet the old libs and use older versions of matplotlib
actuel i use 3.0.2.
i copy the Folders matplotlib, matplotlib-3.0.2.dist-info and matplotlib-3.0.2-py3.5-nspkg.pth
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(9.5, 6), dpi=450)
ax = fig.gca()
ax.set_xticks(np.arange(tick_scale_x))
ax.set_yticks(np.arange(tick_scale_y))
plt.title(dia_title, fontsize=20, color='black')
plt.xlabel(axis_label_x)
plt.ylabel(axis_label_y)

How to plot remote image (from http url)

This must be easy, but I can't figure how right now without using urllib module and manually fetching remote file
I want to overlay plot with remote image (let's say "http://matplotlib.sourceforge.net/_static/logo2.png"), and neither imshow() nor imread() can load the image.
Any ideas which function will allow loading remote image?
It is easy indeed:
import urllib2
import matplotlib.pyplot as plt
# create a file-like object from the url
f = urllib2.urlopen("http://matplotlib.sourceforge.net/_static/logo2.png")
# read the image file in a numpy array
a = plt.imread(f)
plt.imshow(a)
plt.show()
This works for me in a notebook with python 3.5:
from skimage import io
import matplotlib.pyplot as plt
image = io.imread(url)
plt.imshow(image)
plt.show()
you can do it with this code;
from matplotlib import pyplot as plt
a = plt.imread("http://matplotlib.sourceforge.net/_static/logo2.png")
plt.imshow(a)
plt.show()
pyplot.imread for URLs is deprecated
Passing a URL is deprecated. Please open the URL for reading and pass
the result to Pillow, e.g. with
np.array(PIL.Image.open(urllib.request.urlopen(url))).
Matplotlib suggests using PIL instead. I prefer using imageio as sugested by SciPy:
imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use
imageio.imread instead.
imageio.imread(uri, format=None, **kwargs)
Reads an image from the specified file. Returns a numpy array, which
comes with a dict of meta data at its ‘meta’ attribute.
Note that the image data is returned as-is, and may not always have a
dtype of uint8 (and thus may differ from what e.g. PIL returns).
Example:
import matplotlib.pyplot as plt
from imageio import imread
url = "http://matplotlib.sourceforge.net/_static/logo2.png"
img = imread(url)
plt.imshow(img)