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
Related
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.
I wonder if anyone know what happened to my program in python: as I tried a few different codes to se what would suit me and my task the best I ended up with the error AttributeError: partially initialized module 'numpy' has no attribute 'dtype' (most likely due to a circular import) (I wrote the entire error value at the bottom in case it would be of interest to anyone) and the program I am trying to run is:
import matplotlib.pyplot as plt
# x axis values
x = [1,2,3]
# corresponding y axis values
y = [2,4,1]
# plotting the points
plt.plot(x, y)
# naming the x axis
plt.xlabel('x - axis')
# naming the y axis
plt.ylabel('y - axis')
# function to show the plot
plt.show()
I have read on various pages to try to understand why this occurs but have not become much wiser, I have also renamed all my files in my python folder if any of these would be the problem but this still occurs and. It even occurs for different codes.
As I were trying to uninstall matplotlib with pip uninstall matplotlib I got:
Found existing installation: matplotlib 3.2.2
Uninstalling matplotlib-3.2.2:
Would remove:
/opt/anaconda3/lib/python3.8/site-packages/matplotlib-3.2.2-py3.8-nspkg.pth
/opt/anaconda3/lib/python3.8/site-packages/matplotlib-3.2.2.dist-info/*
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/*
/opt/anaconda3/lib/python3.8/site-packages/mpl_toolkits/axes_grid/*
/opt/anaconda3/lib/python3.8/site-packages/mpl_toolkits/axes_grid1/*
/opt/anaconda3/lib/python3.8/site-packages/mpl_toolkits/axisartist/*
/opt/anaconda3/lib/python3.8/site-packages/mpl_toolkits/mplot3d/*
/opt/anaconda3/lib/python3.8/site-packages/mpl_toolkits/tests/*
/opt/anaconda3/lib/python3.8/site-packages/pylab.py
Proceed (y/n)?
But then I can't answer yes or no for proceed, so its just frozen like that.
Full error: `
File "/Users/idalundmark/Desktop/Programmeringsteknik för matematiker (Labb)/Avklarade labbar/untitled6.py", line 10, in <module>
import matplotlib.pyplot as plt
File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/__init__.py", line 139, in <module>
from . import cbook, rcsetup
File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 32, in <module>
import numpy as np
File "/opt/anaconda3/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/opt/anaconda3/lib/python3.8/site-packages/numpy/core/__init__.py", line 83, in <module>
from . import function_base
File "/opt/anaconda3/lib/python3.8/site-packages/numpy/core/function_base.py", line 2, in <module>
import scipy.interpolate
File "/opt/anaconda3/lib/python3.8/site-packages/scipy/__init__.py", line 79, in <module>
from numpy.random import rand, randn
File "/opt/anaconda3/lib/python3.8/site-packages/numpy/random/__init__.py", line 181, in <module>
from . import _pickle
File "/opt/anaconda3/lib/python3.8/site-packages/numpy/random/_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "mtrand.pyx", line 1, in init numpy.random.mtrand
AttributeError: partially initialized module 'numpy' has no attribute 'dtype' (most likely due to a circular import)`
Thanks in advance!
I have tried to run the following code. but it gives an argument required error in lifelines/plotting.py file. i can't fix it .
import pandas as pd
from lifelines.datasets import load_dd
import matplotlib.pyplot as plt
data = load_dd()
print data.sample(6)
from lifelines import KaplanMeierFitter
kmf = KaplanMeierFitter()
T = data["duration"]
E = data["observed"]
kmf.fit(T, event_observed=E)
kmf.survival_function_.plot()
plt.title('Survival function of political regimes');
kmf.plot()
plt.show()
but it gives the following error
Traceback (most recent call last): File "/Users/rabindra/PycharmProjects/SurvivalAnalysis/sources/main.py", line 17, in <module>
kmf.plot() File "/Library/Python/2.7/site-packages/lifelines/plotting.py", line 331, in plot
set_kwargs_color(kwargs) File "/Library/Python/2.7/site-packages/lifelines/plotting.py", line 223, in set_kwargs_color
kwargs["ax"]._get_lines.get_next_color()) AttributeError: '_process_plot_var_args' object has no attribute 'get_next_color'
I was facing the same issue.
Upgraded lifelines to 0.14.0 and matplotlib to 2.2.2 and it works.
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?
I am trying to read a *.wav file using scipy. I do the following:
import scipy
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
As a result of this code I get:
Traceback (most recent call last):
File "test3.py", line 2, in <module>
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
AttributeError: 'module' object has no attribute 'io'
Does anybody know what is wrong here? Thank you in advance.
As the error says, scipy module does not have 'io'.
io.wavfile is a submodule, you need to from scipy.io import wavfile and then do wavfile.read("/usr/share/sounds/purple/receive.wav")
This gives me an error with the file you are using as an example, however...