Error in importing NLTK : - python

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

Related

How do I resove the ImportError encountered while using the fssa package in python?

I am using python from a anaconda installation and using the python
notebook. From the jupyer notebook (ipython) I import fssa like:
import fssa
I get the following error message (see below).
Any help from you will be appreciated.
I have tried uninstalling and reinstalling scipy, numpy, and fssa and reinstalling
them, but the problem seems to remain.
ImportError Traceback (most recent call last)
/tmp/ipykernel_218856/781571052.py in <module>
----> 1 import fssa
~/anaconda3/lib/python3.9/site-packages/fssa/__init__.py in <module>
82
83 import pkg_resources
---> 84 from .fssa import scaledata, quality, autoscale
85
86 __version__ = pkg_resources.get_distribution(__name__).version
~/anaconda3/lib/python3.9/site-packages/fssa/fssa.py in <module>
46 import scipy.optimize
47
---> 48 from .optimize import _minimize_neldermead
49
50
~/anaconda3/lib/python3.9/site-packages/fssa/optimize.py in <module>
11 import numpy
12 from numpy import asfarray
---> 13 from scipy.optimize.optimize import (OptimizeResult,
14 _status_message, wrap_function)
15
ImportError: cannot import name 'wrap_function' from 'scipy.optimize.optimize'
(/home/debasish/anaconda3/lib/python3.9/site-packages/scipy/optimize/optimize.py)

Error while importing gensim package in colab

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
>>>

how to correct ImportError: cannot import name 'murmurhash3_32'

I installed scikit-learn library in python using the command
pip install -U scikit-learn
When I am trying to import the library or it's module like
from sklearn.model_selection import train_test_split
or simply import sklearn
I am getting the error
ImportError Traceback (most recent call last)
<ipython-input-24-73edc048c06b> in <module>()
----> 1 from sklearn.model_selection import train_test_split
c:\users\ajain9\appdata\local\programs\python\python36-32\lib\site-packages\sklearn\__init__.py in <module>()
132 else:
133 from . import __check_build
--> 134 from .base import clone
135 __check_build # avoid flakes unused variable error
136
c:\users\ajain9\appdata\local\programs\python\python36-32\lib\site-packages\sklearn\base.py in <module>()
11 from scipy import sparse
12 from .externals import six
---> 13 from .utils.fixes import signature
14 from . import __version__
15
c:\users\ajain9\appdata\local\programs\python\python36-32\lib\site-packages\sklearn\utils\__init__.py in <module>()
7 import warnings
8
----> 9 from .murmurhash import murmurhash3_32
10 from .validation import (as_float_array,
11 assert_all_finite,
ImportError: cannot import name 'murmurhash3_32'
Any reason this error might be happening?
I am using Python version 3.6.3 Numpy v 1.13.3 pandas v 0.21.0
I am using windows
Try using virutalenv and install all the libraries required there, it worked for me.

scikit-learn error: libquadmath.so.0: cannot open shared object file: No such file or directory

I got this erreur when I've tried to import scikit learn to my python 3.5 (jupyter notebook):
from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-139cc3505715> in <module>()
----> 1 from sklearn.model_selection import train_test_split
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/__init__.py in <module>()
55 else:
56 from . import __check_build
---> 57 from .base import clone
58 __check_build # avoid flakes unused variable error
59
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/base.py in <module>()
10 from scipy import sparse
11 from .externals import six
---> 12 from .utils.fixes import signature
13 from .utils.deprecation import deprecated
14 from .exceptions import ChangedBehaviorWarning as _ChangedBehaviorWarning
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/utils/__init__.py in <module>()
9
10 from .murmurhash import murmurhash3_32
---> 11 from .validation import (as_float_array,
12 assert_all_finite,
13 check_random_state, column_or_1d, check_array,
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/utils/validation.py in <module>()
16
17 from ..externals import six
---> 18 from ..utils.fixes import signature
19 from .deprecation import deprecated
20 from ..exceptions import DataConversionWarning as _DataConversionWarning
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/utils/fixes.py in <module>()
289 from ._scipy_sparse_lsqr_backport import lsqr as sparse_lsqr
290 else:
--> 291 from scipy.sparse.linalg import lsqr as sparse_lsqr
292
293
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/scipy/sparse/linalg/__init__.py in <module>()
110 from __future__ import division, print_function, absolute_import
111
--> 112 from .isolve import *
113 from .dsolve import *
114 from .interface import *
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/__init__.py in <module>()
4
5 #from info import __doc__
----> 6 from .iterative import *
7 from .minres import minres
8 from .lgmres import lgmres
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/iterative.py in <module>()
5 __all__ = ['bicg','bicgstab','cg','cgs','gmres','qmr']
6
----> 7 from . import _iterative
8
9 from scipy.sparse.linalg.interface import LinearOperator
ImportError: libquadmath.so.0: cannot open shared object file: No such file or directory
the scikit learn 0.18.2 package is already installed and I can see it on the list when I run conda list(I got the same error with the last version 0.19.1).
I work with the Anaconda 3 (conda 4.2.2)
you'r python installation has missing dynamically linked shared library which is used by scipy.
generally when you install anaconda under lib directory this shared objects are present and respective paths are exported in environment for dynamic linking.
check if this files are there under the lib directory of your anaconda installation.
e.g:-
/anaconda3/lib/libquadmath.0.dylib
if it is not there then please reinstall anaconda it will solve your problem.
if this file exists then please check your environment path. which must have anaconda installation path in there list.

Scikit-learn fails to import only in Jupyter notebook

I have Anaconda installed on OS X. I am able to import sklearn from a python terminal and an IPython terminal. But when I try to import sklearn from a Jupyter notebook, I get the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-8fd979e02004> in <module>()
----> 1 import sklearn
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/__init__.py in <module>()
55 else:
56 from . import __check_build
---> 57 from .base import clone
58 __check_build # avoid flakes unused variable error
59
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/base.py in <module>()
10 from scipy import sparse
11 from .externals import six
---> 12 from .utils.fixes import signature
13 from .utils.deprecation import deprecated
14 from .exceptions import ChangedBehaviorWarning as _ChangedBehaviorWarning
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/__init__.py in <module>()
9
10 from .murmurhash import murmurhash3_32
---> 11 from .validation import (as_float_array,
12 assert_all_finite,
13 check_random_state, column_or_1d, check_array,
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/validation.py in <module>()
16
17 from ..externals import six
---> 18 from ..utils.fixes import signature
19 from .deprecation import deprecated
20 from ..exceptions import DataConversionWarning as _DataConversionWarning
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/fixes.py in <module>()
288 from ._scipy_sparse_lsqr_backport import lsqr as sparse_lsqr
289 else:
--> 290 from scipy.sparse.linalg import lsqr as sparse_lsqr
291
292
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/__init__.py in <module>()
110 from __future__ import division, print_function, absolute_import
111
--> 112 from .isolve import *
113 from .dsolve import *
114 from .interface import *
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/__init__.py in <module>()
4
5 #from info import __doc__
----> 6 from .iterative import *
7 from .minres import minres
8 from .lgmres import lgmres
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/iterative.py in <module>()
5 __all__ = ['bicg','bicgstab','cg','cgs','gmres','qmr']
6
----> 7 from . import _iterative
8
9 from scipy.sparse.linalg.interface import LinearOperator
ImportError: dlopen(/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/_iterative.so, 2): Library not loaded: /usr/local/lib/libgcc_s.1.dylib
Referenced from: /Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/_iterative.so
Reason: image not found
I can import numpy, scipy, and pandas fine from the Jupyter notebook. It is just sklearn that fails.
I have also tried creating a new conda environment (conda create -n test_env jupyter notebook matplotlib scipy numpy pandas scikit-learn), but the error persists in the new environment as well.
I managed to figure out what was going on, so I'll post my solution here in case anyone else runs into the same problem. As it turns out, I had modified the DYLD_FALLBACK_LIBRARY_PATH environment variable in my .bashrc file when I had installed another piece of software. Restoring this environment variable to its default fixed the problem for me.
(Incidentally, scikit-learn was failing to import in a standard Python terminal as well. I didn't initially realize this because I was testing the Python terminal in an environment in which I had accidentally restored the environment variables to their defaults, overwriting the change I had made in my .bashrc file.)

Categories

Resources