I am running a very simple Python script:
from tftb.generators import amgauss, fmlin
I get this error:
C:\Users\Anaconda3\envs\tf_gpu\lib\site-packages\tftb-0.0.1-py3.6.egg\tftb\processing\affine.py in <module>
12
13 import numpy as np
---> 14 from matplotlib.mlab import find
15 from scipy.signal import hilbert
16 from scipy.optimize import brenth, newton
ImportError: cannot import name 'find'
I believe find is no longer in versions >=3. How can I get around this without downgrading Matplotlib?
The code of the matplotlib.mlab.find function was literally
import numpy as np
def find(condition):
res, = np.nonzero(np.ravel(condition))
return res
You may replace any occurance with that function.
Related
In Python when write #
import sensitivity
i found that error
ImportError Traceback (most recent call last)
in
----> 1 import sensitivity
~\anaconda3\envs\name_of_my_env\lib\site-packages\sensitivity_init_.py in
3 visualizations including gradient DataFrames and hex-bin plots
4 """
----> 5 from sensitivity.main import SensitivityAnalyzer
~\anaconda3\envs\name_of_my_env\lib\site-packages\sensitivity\main.py in
9 from IPython.display import display, HTML
10
---> 11 from sensitivity.df import sensitivity_df, _style_sensitivity_df, _two_variable_sensitivity_display_df
12 from sensitivity.hexbin import _hex_figure_from_sensitivity_df
13
~\anaconda3\envs\name_of_my_env\lib\site-packages\sensitivity\df.py in
6
7 import pandas as pd
----> 8 import pd_utils
9 from pandas.io.formats.style import Styler
10 import numpy as np
~\anaconda3\envs\name_of_my_env\lib\site-packages\pd_utils_init_.py in
37 join_col_strings
38 )
---> 39 from pd_utils.plot import plot_multi_axis
40
41
~\anaconda3\envs\name_of_my_env\lib\site-packages\pd_utils\plot.py in
2
3 import pandas as pd
----> 4 from pandas.plotting._matplotlib.style import _get_standard_colors
5 import matplotlib.pyplot as plt
6
ImportError: cannot import name '_get_standard_colors' from 'pandas.plotting._matplotlib.style' (C:\Users\DELL\anaconda3\envs\name_of_my_env\lib\site-packages\pandas\plotting_matplotlib\style.py)
There is a mistake on the plot.py script of the sensitivity library. You need to change the import from from pandas.plotting._matplotlib.style import _get_standard_colors to from pandas.plotting._matplotlib.style import get_standard_colors
Therefore just removing the underscore
I'm the creator of sensitivity and I just put a fix for this (see GitHub issue).
pip install --upgrade sensitivity should should get you v0.2.6 or newer and fix the issue (see releases).
It was caused by newer versions of Pandas that moved things around and broke another one of my packages, pd_utils, which this depended on. It turned out the functionality I needed from pd_utils was very small and unrelated to the part that was breaking, so I refactored things a bit to remove pd_utils as a dependency (this should keep it more stable going forward as well).
I am working on a small library and I need to know can I import modules like numpy, sklearn and etc. Using functions. For example:
def ml():
import numpy as np
import pandas as pd
x = np.array([1,2,647,345,3,7,3,8,36,64])
Is this possible ?
Simply can I import a module using a function and then use that later outside the function
The main idea is when the user calls the function ml he has all the modules related to machine learning imported and then he can use them. X = np.array was just kind of an example.
UPDATED
This should work
import importlib
def importmd(modulex):
return importlib.import_module(modulex) #Returning the module
np = importmd("numpy") #Same as import numpy as np
In the following code I'm getting errors when trying to call librosa.grifflim, telling me the attribute does not exist.
import os
from matplotlib import pyplot as plt
import librosa
import librosa.display
import IPython.display as ipd
import numpy as np
import cv2
S = cv2.imread('spectrograms/CantinaBand60.wav10.jpg')
D = librosa.amplitude_to_db(np.abs(S), ref=np.max)
signal = librosa.griffinlim(D)
sf.write('test.wav', signal, 352000)
I've upgraded librosa, and I still encounter the error. The documentation page for this function no longer seems to exist either. I've also tried import just that module using librosa.griffinlim but it continues to tell me this module doesn't exist. Was this function removed during a recent version? If so, is there another function I can use to apply the griffin lim algorithm?
librosa.griffinlim was introduced in librosa 0.7.0. So you need to have that version or later. You can check this using the following code.
import librosa; print(librosa.__version__)
I'm trying to import a series of modules into my Python 3.5 code. I use the following code to import:
# import packages for analysis and modeling
import pandas as pd # data frame operations; use pandas 0.18
from pandas.tools.rplot import RPlot, TrellisGrid, GeomPoint, \
ScaleRandomColour # trellis/lattice plotting
import numpy as np # arrays and math functions
from scipy.stats import uniform # for training-and-test split
import statsmodels.api as sm # statistical models (including regression)
import statsmodels.formula.api as smf # R-like model specification
import matplotlib.pyplot as plt # 2D plotting
When i use this code, I receive the following error:
ImportError Traceback (most recent call last)
/var/folders/zy/snhf2bh51v33ny6nf7fyr4wh0000gn/T/tmpdxMQ0Y.py in <module>()
7 # import packages for analysis and modeling
8 import pandas as pd # data frame operations; use pandas 0.18
----> 9 from pandas.tools.rplot import RPlot, TrellisGrid, GeomPoint, \
10 ScaleRandomColour # trellis/lattice plotting
11 import numpy as np # arrays and math functions
ImportError: No module named 'pandas.tools.rplot'
I tried this code with "pd" and with "pandas" written out. I confirmed that pandas was installed by manually typing in import pandas as pd and then confirming its existence by typing in "pd" and receiving the following message: <module 'pandas' from '/Users/me/Library/Enthought/Canopy/edm/envs/User/lib/python3.5/site-packages/pandas/__init__.py'>
What is causing this to happen?
Renaming it during import with as doesn't mean Python will be able to find the original module (pandas) when you use the name pd at a later import statement. Python will look for a module named pd which it will not find.
Since pd does not correspond to some module while pandas does, you'll need to use from pandas import tools in order to get it to work.
Title says it all, I somehow can not find that function. Obviously it's inside the Numpy package (numpy.core.umath.deg2rad) and I've tried importing it but to no avail. Anyone care to chime in?
import numpy as np - np.deg2rad doesn't even show up
from numpy import* - umath.deg2rad shows up, but it raises an error, ''name 'umath' is not defined''
from numpy.core.umath import deg2rad
# then
deg2rad(...)
Or
import numpy as np
np.core.umath.deg2rad(...)