Tifffile.imshow() KeyError: 'matplotlib.pyplot' - python

I used the Tifffile module's imshow () method to display the tiff image in Python 3.5.2.
The code is as follows:
import tifffile as tiff
IM_ID = '6120_2_2'
im_rgb = tiff.imread('/home/roy/image&csv/image/{}.tif'.format(IM_ID)).transpose([1, 2, 0])
im_size = im_rgb.shape[:2]
tiff.imshow(im_rgb)
But there is an error:
Traceback (most recent call last):
File "/home/roy/PycharmProjects/CSV2Ploy/csv2ploy.py", line 49, in <module>
tiff.imshow(im_rgb)
File "/usr/local/lib/python3.5/dist-packages/tifffile/tifffile.py", line 6349, in imshow
pyplot = sys.modules['matplotlib.pyplot']
KeyError: 'matplotlib.pyplot'
I think it must be my development environment missing the matplotlib.pyplot module. So I checked the matplotlib directory, but found that the directory does have pyplot.py file.
The terminal queries the pyplot.py file
I have a lot of information on the Internet, but most are import matplotlib.pyplot problems, some people can help me solve this problem?

Related

Pycharm Error: ModuleNotFoundError: No module named 'pymoo.algorithms'; 'pymoo' is not a package

I've tried to run the example code from pymoo for NSGA2 in PyCharm.
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.factory import get_problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter
problem = get_problem("zdt1")
algorithm = NSGA2(pop_size=100)
res = minimize(problem,
algorithm,
('n_gen', 200),
seed=1,
verbose=False)
plot = Scatter()
plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7)
plot.add(res.F, facecolor="none", edgecolor="red")
plot.show()
It gives me always this Error:
/Users/myname/opt/miniconda3/envs/namename/bin/python /Users/myname/PycharmProjects/name/namename/pymoo.py
Traceback (most recent call last):
File "/Users/myname/PycharmProjects/name/namename/pymoo.py", line 1, in <module>
from pymoo.algorithms.moo.nsga2 import NSGA2
File "/Users/mynae/PycharmProjects/name/namename/pymoo.py", line 1, in <module>
from pymoo.algorithms.moo.nsga2 import NSGA2
ModuleNotFoundError: No module named 'pymoo.algorithms'; 'pymoo' is not a package
I have already downloaded pymoo under the preferences and when I try to download pymoo in the terminal again it says that all packages are already installed.
Can anyone help?
Rename your file, for example to pymoo_test.py (or something else entirely) and it should work.
Your stack trace tells me that your file is called pymoo.py:
File "/Users/mynae/PycharmProjects/name/namename/pymoo.py", line 1, in <module>
The file name is what is causing your problem. What's happening is that the imports are being tried to be imported from your pymoo.py file due to the name and you trying to import from pymoo.<...> in the same file.

Python and matplotlib: when I try to import, it send a not valid cycler construction error

I've wanted to try matplotlib for the first time but when I import it, there is an error.
The only line of my code is:
from matplotlib import pyplot as plt
but when I run this, I have this error:
Traceback (most recent call last):
File "/Users/mylaptop/Desktop/main.py", line 1, in <module>
from matplotlib import pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 903, in <module>
rcParamsDefault = _rc_params_in_file(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 834, in _rc_params_in_file
config[key] = val # try to convert to proper type or raise
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 678, in __setitem__
raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key axes.prop_cycle: 'cycler('color', ['1f77b4', 'ff7f0e', '2ca02c', 'd62728', '9467bd', '8c564b', 'e377c2', '7f7f7f', 'bcbd22', '17becf'])' is not a valid cycler construction: name 'np' is not defined
I have no idea on how to fix it.
I am on Mac and I use the Pycharm IDE.
Looking at the code of matplotlib/__init__.py, the Python library numpy is a requirement of matplotlib, but the error:
name 'np' is not defined
seems to tell us that it's not (correctly) installed in your system.

Error on small python script using the library librosa

I'm playing around with the python library librosa. I'm trying to show the waveform of my audio file, but I'm always getting the following
Traceback (most recent call last):
File "main.py", line 11, in <module>
librosa.display.waveplot(y, sr=sr)
File "/Users/lukasnehlsen/Library/Python/2.7/lib/python/site-packages/librosa/display.py", line 444, in waveplot
kwargs.setdefault('color', next(axes._get_lines.prop_cycler)['color'])
AttributeError: '_process_plot_var_args' object has no attribute 'prop_cycler'
This is my full code:
import matplotlib.pyplot as plt
import librosa
import librosa.display
y, sr = librosa.load('kick.wav', mono=False, duration=10)
plt.figure()
plt.subplot(3, 1, 2)
librosa.display.waveplot(y, sr=sr)
plt.title('Stereo')
plt.show()
I really did the same like on th documentation and don't really understand the error. I'm new into this.
If someone can help me, I would be very thankful :)
Best regards
Lukas

No module named Image windows ananconda

from PIL import Image
from pytesser import *
image_file = 'D:\plate.jpg'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print "=====output=======\n"
print text
it gets me error that
C:\Users\KEN\Anaconda2\python.exe C:/Users/KENIL/PycharmProjects/plate/ocr.py
Traceback (most recent call last):
File "C:/Users/KEN/PycharmProjects/plate/ocr.py", line 2, in <module>
from pytesser import *
File "C:\Users\KEN\PycharmProjects\plate\pytesser.py", line 6, in <module>
import Image
ImportError: No module named Image
even though i have installed ananconda properly as well as pillow screenshot of package installed
The code you posted doesn't have the error. From the error message it seems that the error is in the module pytesser.py, where you probably use Image (in line 6 :-) ) without importing it.

netCDF4.Variable.__getitem__ not implemented for this type

I'm stuck with a simple netCDF4 example.
import numpy as np
from netCDF4 import Dataset
argo_file = Dataset('R20130811_prof.nc', 'r')
n_prof = len(argo_file.dimensions["N_PROF"])
platform_numbers = argo_file.variables["PLATFORM_NUMBER"]
for profile_idx in range(0, n_prof):
print platform_numbers[profile_idx]
I get the following error in running it:
$python netcdf4_ex.py
Traceback (most recent call last):
File "netcdf4_ex.py", line 9, in <module>
print platform_numbers[profile_idx]
File "netCDF4.pyx", line 2780, in netCDF4.Variable.__getitem__ (netCDF4.c:34558)
File "netCDF4.pyx", line 2819, in netCDF4.Variable._toma (netCDF4.c:35257)
TypeError: Not implemented for this type
The code snippet is taken from an existing production code so it cannot be wrong. The issue should be somehow related to my netcdf4 installation.
I'm running on my Mac OsX:
Python 2.7
NetCDF 4.3.0
Any hints where to look for a solution?

Categories