When I run this program in Python, it show me this error:
ImportError: No module named skimage.io.
I have already run the command pip install scikit-image, but I still get this error. Can you please help me?
This is my code:
import matplotlib.pyplot as plt
import skimage.io as io
import skimage.color as color
parrots = io.imread('C:\Python27\Example\parrots.bmp')
parrots_hsv= skcolor.convert_colorspace(parrots, 'RGB','HSV')
fig, ax= plt.subplots(nclos = 2, figsize=('8,4'))
ax[0].imshow(parrots)
ax[0].set_title('original image')
restored_image =skcolore.convert_colorspace(parrots_hsv, 'HSV','RGB')
ax[1].imshow(restored_image)
ax[1].set_title('restored image')
plt.show()`enter code here`
I reproduced this error like so:
import math.sqrt as sq
print(sq(4))
Error:
File ".\Solution.py", line 1, in <module>
import math.sqrt as sq
ModuleNotFoundError: No module named 'math.sqrt'; 'math' is not a package
repaired by:
from math import sqrt as sq
print(sq(4))
So I presume if you changed your imports to the below code it might fix it:
from matplotlib import pyplot as plt
from skimage import io as io
from skimage import color as color
In addition, you might want to read a bit here for a simple explanation about imports.
Related
I am trying to import matplotlib in .ipynb file but its not working, none of my files have the same name as _docstring yet I get this error and if I try something in .py file, it works fine.
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
I'm running this in a .ipynb file in VS Code
Output :
ImportError Traceback (most recent call last)
Cell In[3], line 2
1 import numpy as np
----> 2 import matplotlib.pyplot as plt
3 import cv2 as cv
File c:\Users\P****\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\__init__.py:113
109 from packaging.version import parse as parse_version
111 # cbook must import matplotlib only within function
112 # definitions, so it is safe to import from it here.
--> 113 from . import _api, _version, cbook, _docstring, rcsetup
114 from matplotlib.cbook import sanitize_sequence
115 from matplotlib._api import MatplotlibDeprecationWarning
ImportError: cannot import name '_docstring' from partially initialized module 'matplotlib' (most likely due to a circular import) (c:\Users\P****\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\__init__.py)
But if I try to import matplotlib in .py file like
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1,10,0.1)
y = x**2
plt.plot(x,y)
plt.show()
It runs fine, no issues.
Try deleting matplotlib folder and reinstalling it.
Full path: AppData\Roaming\Python\Python39\site-packages\matplotlib
It worked for me.
I'm assigned to run a python script, that imports several module
#filename: animate_vid_v6.py
import numpy as np
import pandas as pd
import imageio
from trackviz import animate
import sys
from matplotlib.patches import Circle
from operator import itemgetter
import colorsys
after I installed all the required modules, I get this error message.
Traceback (most recent call last):
File "<some_directories>\animate_vid_v6.py", line 4, in <mo
dule>
from trackviz import animate
File "C:\Python39\lib\site-packages\trackviz\animate.py", line 9, in <module>
from trackviz.tools import FigureAxes
File "C:\Python39\lib\site-packages\trackviz\tools.py", line 3, in <module>
from mpl_toolkits.axes_grid1 import Divider, LocatableAxes, Size
ImportError: cannot import name 'LocatableAxes' from 'mpl_toolkits.axes_grid1' (
C:\Python39\lib\site-packages\mpl_toolkits\axes_grid1\__init__.py)
After I scrutinize that message, it is turn out that the LocatableAxes is no longer exists in scripts inside the C:\Python39\lib\site-packages\mpl_toolkits\axes_grid1 directory.
As you can see here, at the C:\Python39\lib\site-packages\mpl_toolkits\axes_grid1\__init__.py, there are no LocatableAxes module.
from . import axes_size as Size
from .axes_divider import Divider, SubplotDivider, make_axes_locatable
from .axes_grid import Grid, ImageGrid, AxesGrid
from .parasite_axes import host_subplot, host_axes
Does anybody has an idea /suggestions to fix this problem? thanks.
The LocatableAxes classes have been deprecated in Matplotlib 3.0.0, but it seems trackviz hasn't been updated since then to avoid using these classes. Indeed, the trackviz GitHub repository hasn't been updated for about three years.
If you really want to use trackviz you will have to install an older version of Matplotlib.
How can I save plot from mglearn? I tried this code but it does not work.
import numpy as np
import matplotlib.pyplot as plt
import mglearn
from fpdf import FPDF
f = mglearn.plots.plot_knn_classification(n_neighbors=3)
f.savefig("n_neighbors.pdf", bbox_inches='tight')
The error was AttributeError: 'NoneType' object has no attribute 'savefig'.
Thanks
As the mglearn package uses matplotlib.pyplot's plotting mechanics you can use their saving mechanics, like so.
mglearn.plots.plot_knn_classification(n_neighbors=3)
plt.savefig("n_neighbors.pdf", bbox_inches='tight')
from sklearn.neighbors import KNeighborsClassifier
import matplotlib.pyplot as plt
import mglearn.plots
import numpy as np
import mglearn
from fpdf import FPDF
X, y = mglearn.datasets.make_forge()
mglearn.plots.plot_knn_classification(n_neighbors=3)
plt.savefig("n_neighbors.pdf", bbox_inches='tight')
This code work.
This is my code.
import sys, os
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from scipy import *
sys.path.insert(0, 'C:/research')
im = Image.open('C:/research/1.jpg')
hei, wei = im.height, im.width
im_bicubic = im.resize((wei,hei), im.BICUBIC)
im.save('C:/research/1ori.jpg') #original image
im_bicubic.save('C:/research/1bic.jpg') #Images with bicubic applied
But I get this error.
AttributeError: 'JpegImageFile' object has no attribute 'BICUBIC'
Why is this message coming up?
.bmp, the same message pops up.
What should I do?
You need to use PIL.Image.BICUBIC instead of im.BICUBIC.
So you need to change:
im_bicubic = im.resize((wei,hei), im.BICUBIC)
to
im.resize((wei,hei),PIL.Image.BICUBIC)
You also need to import pil like so:
import PIL
I get this error when I try to run a program that uses SciPy 0.7.2.
from scipy.optimize.linesearch import line_search_wolfe2, line_search_wolfe1
ImportError: cannot import name line_search_wolfe2
Why does that happen?