cannot import name 'asanyarray' - python

I'm currently having trouble importing some simple packages.
I'm working on pycharm professional in a virtual environment.
just trying to load;
import pandas as pd
import numpy as np
from sklearn.ensemble import IsolationForest
from sklearn.ensemble._iforest import _average_path_length
import shap
importError Traceback (most recent call last)
<ipython-input-1-5b7f1bf909af> in <module>
----> 1 import pandas as pd
2 import numpy as np
3 from sklearn.ensemble import IsolationForest
4 from sklearn.ensemble._iforest import _average_path_length
5 import shap
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pandas\__init__.py in <module>
14
15 if missing_dependencies:
---> 16 raise ImportError(
17 "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
18 )
ImportError: Unable to import required dependencies:
numpy: cannot import name 'asanyarray' from 'numpy.core.multiarray' (C:\Users\James\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\numpy\core\multiarray.py
I've never come across this error before so don't know how to fix.

Related

No module named 'sklearn.neighbors.base' still existed after all the suggestions what I can take

I learned a lot of solutions from this website, but still cannot solve the problem. My code is as follows for your review:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import missingno as msno
import altair as alt
from statsmodels.graphics.mosaicplot import mosaic
from scipy.stats import chi2_contingency
import plotly.express as px
from pandas.plotting import parallel_coordinates
from wordcloud import WordCloud
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
from scipy.spatial import distance
!pip install sklearn
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
from sklearn.impute import KNNImputer
from missingpy import MissForest
import sklearn.neighbors._base
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
import warnings
warnings.filterwarnings("ignore")
And still shows the error: ModuleNotFoundError: No module named 'sklearn.neighbors.base' I've tried to do the follows:
pip install -U imbalanced-learn ;
pip install -U scikit-learn
ans there was still of no use
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_11280/2643854484.py in <module>
26 from sklearn.impute import IterativeImputer
27 from sklearn.impute import KNNImputer
---> 28 from missingpy import MissForest
29 import sklearn.neighbors._base
30 sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
C:\ProgramData\Anaconda3\lib\site-packages\missingpy\__init__.py in <module>
----> 1 from .knnimpute import KNNImputer
2 from .missforest import MissForest
3
4 __all__ = ['KNNImputer', 'MissForest']
C:\ProgramData\Anaconda3\lib\site-packages\missingpy\knnimpute.py in <module>
11 from sklearn.utils.validation import check_is_fitted
12 from sklearn.utils.validation import FLOAT_DTYPES
---> 13 from sklearn.neighbors.base import _check_weights
14 from sklearn.neighbors.base import _get_weights
15
ModuleNotFoundError: No module named 'sklearn.neighbors.base'
Finally, I solved the problem!!
I should write this before import missingpy, not behind it.
import sklearn.neighbors._base
import sys
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
from missingpy import MissForest
done.

Scipy cannot import median_abs_deviation

I'm using a program called galpro which uses may packages, including scipy. When I use the command
import galpro as gp
I am then given the error:
ImportError Traceback (most recent call last)
<ipython-input-7-6eb7571a326c> in <module>
----> 1 import galpro as gp
~/galpro/galpro/__init__.py in <module>
----> 1 from .model import Model
~/galpro/galpro/model.py in <module>
8 import joblib
9 import h5py
---> 10 from .validation import Validation
11 from .plot import Plot
12 from .utils import convert_1d_arrays, create_directories
~/galpro/galpro/validation.py in <module>
2 import numpy as np
3 import h5py
----> 4 from .plot import Plot
5 from .utils import load_posteriors, create_templates
6 from .conf import set_plot_params
~/galpro/galpro/plot.py in <module>
4 import seaborn as sns
5 import statsmodels.api as sm
----> 6 from .utils import *
7 from .conf import set_plot_params
8
~/galpro/galpro/utils.py in <module>
3 import h5py
4 import numpy as np
----> 5 from scipy.stats import entropy, kstest, median_abs_deviation, cramervonmises
6
7
ImportError: cannot import name 'median_abs_deviation' ---------------------------------------------------------------------------
I have tried reinstalling scipy and this didn't help. According to documentation, the median_abs_deviation module should work with scipy 1.3.0 onwards, and I'm using 1.5.4. I have also tried reinstalling different versions of scipy and this has not helped either.

Facing Import Error when importing esda and libpysal libraries

Even though I have installed both the libraries several times using different orders in different virtual environments, I'm still facing an issue where I'm not able to import and use certain geospatial libraries like esda and libpysal. The following error shows up:
ImportError Traceback (most recent call last)
C:\Users\SLAADM~1\AppData\Local\Temp/ipykernel_35328/2667884714.py in <module>
3 import numpy as np
4 import matplotlib.pyplot as plt
----> 5 import esda
6 import libpysal as lps
7 import pysal
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\esda\__init__.py in <module>
5
6 """
----> 7 from . import adbscan
8 from .gamma import Gamma
9 from .geary import Geary
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\esda\adbscan.py in <module>
8 import pandas
9 import numpy as np
---> 10 from libpysal.cg.alpha_shapes import alpha_shape_auto
11 from scipy.spatial import cKDTree
12 from collections import Counter
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\__init__.py in <module>
25 Tools for creating and manipulating weights
26 """
---> 27 from . import cg
28 from . import io
29 from . import weights
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\cg\__init__.py in <module>
9 from .sphere import *
10 from .voronoi import *
---> 11 from .alpha_shapes import *
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\cg\alpha_shapes.py in <module>
22
23 try:
---> 24 import pygeos
25
26 HAS_PYGEOS = True
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\pygeos\__init__.py in <module>
----> 1 from .lib import GEOSException # NOQA
2 from .lib import Geometry # NOQA
3 from .lib import geos_version, geos_version_string # NOQA
4 from .lib import geos_capi_version, geos_capi_version_string # NOQA
5 from .decorators import UnsupportedGEOSOperation # NOQA
ImportError: DLL load failed while importing lib: The specified procedure could not be found.
Would really appreciate any help in making this work. Please throw any suggestions you might have at me.
install pygeos i.e conda install pygeos
it worked for me
I found same issue when running example code from a couple of years ago. The pysal API has changed.
Import libpysal first then import the esda libraries eg
import libpysal
from esda.moran import Moran
from esda.smaup import Smaup
see
https://pysal.org/esda/generated/esda.Moran.html

NLP / ModuleNotFoundError

import numpy as np
%matplotlib notebook
import matplotlib.pyplot as plt
plt.style.use ('ggplot')
from sklearn.manifold import TSNE
from sklearn.decomposition import PCA
from gensim.test.utils import datapath, get_tmpfile
from gensim.models import KeyedVectors
from gensim.scripts.glove2word2vec import glove2word2vec
Hello everyone, I hope you all are doing well. I am new in DL and NLP. As I am learning I came across this error. Can anyone help me solve this issue? thank you all.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-13-8db7eebe6f3e> in <module>
7 from sklearn.decomposition import PCA
8
----> 9 from gensim.test.utils import datapath, get_tmpfile
10 from gensim.models import KeyedVectors
11 from gensim.scripts.glove2word2vec import glove2word2vec
ModuleNotFoundError: No module named 'gensim'

ImportError: cannot import name 'signature'

I am trying to import the package of recmetrics and I have done all the actions mentioned in other posts but it does not work.
The code is as follows
import recmetrics
and the error is
ImportErrorTraceback (most recent call last)
<ipython-input-> in <module>
5 import numpy as np
6 from funcsigs import signature
----> 7 import recmetrics
~/anaconda3/envs/python3/lib/python3.6/site-packages/recmetrics/__init__.py in <module>
----> 1 from .plots import long_tail_plot, mark_plot, mapk_plot, coverage_plot, class_separation_plot, roc_plot, precision_recall_plot
2 from .metrics import mark, coverage, personalization, intra_list_similarity, rmse, mse, make_confusion_matrix, recommender_precision, recommender_recall
~/anaconda3/envs/python3/lib/python3.6/site-packages/recmetrics/plots.py in <module>
5 from matplotlib.lines import Line2D
6 from sklearn.metrics import roc_curve, auc, precision_recall_curve, average_precision_score
----> 7 from sklearn.utils.fixes import signature
ImportError: cannot import name 'signature'
I have tried the following steps:
!pip freeze | grep recmetrics
recmetrics==0.0.12
First I tried :
from sklearn.utils.fixes import signature
Then I tried This :
from funcsigs import signature
Non of them works could you please let me know why it does not work. The python version which I am using is 3.6.10 |Anaconda.
I am using Amazonsage maker and I am wondering how I can SSHing in ~/anaconda3/envs/python3/lib/python3.6/sitepackages/recmetrics/__init__.py
to change from sklearn.utils.fixes import signature to from funcsigs import signature
From: https://github.com/statisticianinstilettos/recmetrics/issues/4
I had to manually change in the plots.py
Instead of from sklearn.utils.fixes import signature use from funcsigs import signature

Categories