ImportError: cannot import name 'mean_absolute_difference'
Tried uninstalling and installing again.
import gensim
ImportError Traceback (most recent call last)
<ipython-input-28-e70e92d32c6e> in <module>()
----> 1 import gensim
2 frames
/usr/local/lib/python3.6/dist-packages/gensim/models/hdpmodel.py in
<module>()
61
62 from gensim import interfaces, utils, matutils
---> 63 from gensim.matutils import dirichlet_expectation,
mean_absolute_difference
64 from gensim.models import basemodel, ldamodel
65
ImportError: cannot import name 'mean_absolute_difference'
I tried installing gensim on my linux using !pip install gensim and after that i imported as you did it worked fine. Like shown below.
>>> !pip install gensim
>>> import gensim
>>> from gensim import interfaces, utils, matutils
>>> from gensim.matutils import dirichlet_expectation, mean_absolute_difference
>>>
Related
I got a problem I can't seem to figure out. The first time I imported Spacy into a Jupyter notebook I had no problems. It just imported it as I expected.
import spacy
nlp = spacy.load('en_core_web_sm')
i tried
import sys
print(sys.executable)
and i got this error
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-21-e4c801bd61f2> in <module>
----> 1 import spacy
2 nlp = spacy.load('en_core_web_sm')
~/Downloads/PREFIX=/home/khbe0387/anaconda3/lib/python3.8/site-packages/spacy/__init__.py in <module>
9
10 # These are imported as part of the API
---> 11 from thinc.api import prefer_gpu, require_gpu, require_cpu # noqa: F401
12 from thinc.api import Config
13
ImportError: cannot import name 'prefer_gpu' from 'thinc.api' (/home/khbe0387/Downloads/PREFIX=/home/khbe0387/anaconda3/lib/python3.8/site-packages/thinc/api.py)
Whenever I try to run the following line of code:
from imblearn.under_sampling import NearMiss
for under-sampling (or over-sampling) imbalanced data on Jupyter notebook, I get this error:
ImportError Traceback (most recent call last)
<ipython-input-21-c701341dce49> in <module>
----> 1 from imblearn.under_sampling import NearMiss
~\anaconda3\lib\site-packages\imblearn\under_sampling\__init__.py in <module>
4 """
5
----> 6 from ._prototype_generation import ClusterCentroids
7
8 from ._prototype_selection import RandomUnderSampler
~\anaconda3\lib\site-packages\imblearn\under_sampling\_prototype_generation\__init__.py in <module>
4 """
5
----> 6 from ._cluster_centroids import ClusterCentroids
7
8 __all__ = ['ClusterCentroids']
~\anaconda3\lib\site-packages\imblearn\under_sampling\_prototype_generation\_cluster_centroids.py in <module>
15 from sklearn.cluster import KMeans
16 from sklearn.neighbors import NearestNeighbors
---> 17 from sklearn.utils import safe_indexing
18
19 from ..base import BaseUnderSampler
ImportError: cannot import name 'safe_indexing' from 'sklearn.utils' (C:\Users\anaconda3\lib\site-packages\sklearn\utils\__init__.py)
For imblearn.under_sampling, did you try reinstalling the package?:
pip install imbalanced-learn
conda:
conda install -c conda-forge imbalanced-learn
in jupyter notebook:
import sys
!{sys.executable} -m pip install <package_name>
If you have scikitlearn>=0.24 (as far as i see there is a dependency for imblearn now,as scikit-learn (>=0.23) https://imbalanced-learn.org/stable/install.html) you may want to try:
try:
from sklearn.utils import safe_indexing
except ImportError:
from sklearn.utils import _safe_indexing
Edit ..\Anaconda3\Lib\site-packages\sklearn\utils\ __init__.py.
Copy def _safe_indexing ... till next def and paste the code with renaming to def safe_indexing... .
Keep previous _safe_indexing as it is.
It solved the issue in this way.
In ~\Anaconda3\Lib\site-packages\yellowbrick\classifier\threshold.py module replace:
from sklearn.utils import indexable, safe_indexing
with
from sklearn.utils import indexable, _safe_indexing
After that, restart the kernel.
I tried
pip install tensorflow
it says it is incompatible with my numpy version(1.20.0)
Then I tried unistall numpy to required version numpy~=1.19.2
Then
pip install fancyimpute
It installed without any errors in AnacondaPromt
But it still not working in Jupyter Notebook
The Error is
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-34-e68ac4972d28> in <module>
16 import tensorflow as tf
17 import numpy.core.multiarray
---> 18 from fancyimpute import KNN
~\anaconda3\lib\site-packages\fancyimpute\__init__.py in <module>
2
3 from .solver import Solver
----> 4 from .nuclear_norm_minimization import NuclearNormMinimization
5 from .matrix_factorization import MatrixFactorization
6 from .iterative_svd import IterativeSVD
~\anaconda3\lib\site-packages\fancyimpute\nuclear_norm_minimization.py in <module>
11 # limitations under the License.
12
---> 13 import cvxpy
14
15 from .solver import Solver
~\anaconda3\lib\site-packages\cvxpy\__init__.py in <module>
16
17 __version__ = "1.1.10"
---> 18 from cvxpy.atoms import *
19 from cvxpy.constraints import NonPos, Zero, SOC, PSD
20 from cvxpy.expressions.expression import Expression
~\anaconda3\lib\site-packages\cvxpy\cvxcore\python\__init__.py in <module>
1 # TODO(akshayka): This is a hack; the swig-auto-generated cvxcore.py
2 # tries to import cvxcore as `from . import _cvxcore`
----> 3 import _cvxcore
ImportError: numpy.core.multiarray failed to import
I had the same issue and I upgraded NumPy by running pip install numpy --upgrade. It worked around for me.
I found a solution right here
Opencv/numpy issue: "module compiled against API version X but this version of numpy is Y"
Here is the table and since my version is 1.19.5(0xd) now,
I uninstalled this version and installed 0xe version of numpy which is 1.20.0.
I am trying to load tensorflow within jupyter notebook and receive the following error:
ImportError Traceback (most recent call last) <ipython-input-1-28a19874e1dd> in <module>()
5 import tensorflow as tf
6 from tensorflow.python.framework import ops
----> 7 from tf_utils import load_dataset, random_mini_batches, convert_to_one_hot, predict
8
9 get_ipython().magic(u'matplotlib inline')
/Pathway/tf_utils.py in <module>()
17 import sys
18 import tensorflow as tf
---> 19 import src.utils as utils
20 import logging
21 from tensorflow.contrib import slim
ImportError: No module named src.utils
I have the latest tensorflow installed and have also added models to the PYTHONPATH via:
export PYTHONPATH="$PYTHONPATH:/Pathway/tfmodels-1.9.0"
Do you know how I can resolve this import error?
To resolve this import error I manually imported the missing functions from the following github repo > https://github.com/andersy005/deep-learning-specialization-coursera/blob/master/02-Improving-Deep-Neural-Networks/week3/Programming-Assignments/tf_utils.py
Error as on screen :
On import of nltk :
ImportError: cannot import name raise_unorderable_types
I've already checked these :
Why shows error "import nltk"?
already.
reinstalled nltk using : pip2 install nltk --upgrade
when I try command line level nltk commands like nltk.download , it still throws the same error
Unable to resolve why, I checked dist_packages for python2.7 , it has nltk in it.
Checked by trying to import Other packages in dist_packages like gensim, It works.
Python version : 2.7.6
IPython Shell Version : 1.2.1
ImportError Traceback (most recent call last)
<ipython-input-1-b06499430ee0> in <module>()
----> 1 import nltk
/usr/local/lib/python2.7/dist-packages/nltk/__init__.py in <module>()
103 # Import top-level functionality into top-level namespace
104
--> 105 from collocations import *
106 from decorators import decorator, memoize
107 from featstruct import *
/usr/local/lib/python2.7/dist-packages/nltk/collocations.py in <module>()
34 from operator import itemgetter as _itemgetter
35
---> 36 from nltk.probability import FreqDist
37 from nltk.util import ingrams
38 from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
/usr/local/lib/python2.7/dist-packages/nltk/probability.py in <module>()
46 from operator import itemgetter
47 from itertools import imap, islice
---> 48 from collections import defaultdict
49
50 ##//////////////////////////////////////////////////////
/usr/local/lib/python2.7/dist-packages/nltk/collections.py in <module>()
20 from six import text_type
21
---> 22 from nltk.internals import slice_bounds, raise_unorderable_types
23 from nltk.compat import python_2_unicode_compatible
24
ImportError: cannot import name raise_unorderable_types