ModuleNotFoundError: No module named 'numpy.testing' - python

I keep trying to import sklearn but I when I do I get the error [ModuleNotFoundError: No module named 'numpy.testing']. I have upgraded numpy, pandas, scipy as well as scikit-learn to the latest versions but I still keep getting the same error. Any idea why. Here is the full error below:
'''
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-152-b7c74cbf5af0> in <module>
----> 1 import sklearn
~\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
80 from . import _distributor_init # noqa: F401
81 from . import __check_build # noqa: F401
---> 82 from .base import clone
83 from .utils._show_versions import show_versions
84
~\anaconda3\lib\site-packages\sklearn\base.py in <module>
15 from . import __version__
16 from ._config import get_config
---> 17 from .utils import _IS_32BIT
18 from .utils._tags import (
19 _DEFAULT_TAGS,
~\anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>
27 from ..exceptions import DataConversionWarning
28 from .deprecation import deprecated
---> 29 from .fixes import parse_version, threadpool_info
30 from ._estimator_html_repr import estimator_html_repr
31 from .validation import (
~\anaconda3\lib\site-packages\sklearn\utils\fixes.py in <module>
17 import numpy as np
18 import scipy
---> 19 import scipy.stats
20 import threadpoolctl
21 from .._config import config_context, get_config
~\anaconda3\lib\site-packages\scipy\stats\__init__.py in <module>
465 from ._warnings_errors import (ConstantInputWarning, NearConstantInputWarning,
466 DegenerateDataWarning, FitError)
--> 467 from ._stats_py import *
468 from ._variation import variation
469 from .distributions import *
~\anaconda3\lib\site-packages\scipy\stats\_stats_py.py in <module>
35 from numpy import array, asarray, ma
36 from numpy.lib import NumpyVersion
---> 37 from numpy.testing import suppress_warnings
38
39 from scipy.spatial.distance import cdist
ModuleNotFoundError: No module named 'numpy.testing'
'''

This cause due to the numpy version you are using. Therefore you have to downgrade your numpy version to 1.16.4. Use following command.
sudo pip uninstall numpy
pip install numpy==1.16.4
Reference :
https://github.com/DeepLabCut/Docker4DeepLabCut2.0/issues/26

Related

What would prevent scikit-learn, and more specifically sklearn.base, from importing into Python?

I cannot import any part of scikit-learn library package in Python. I need sklearn.linear_model.LinearRegression but have tried importing various scikit-learn packages each without success. Has anyone had a similar issues with BaseEstimator, or see a solution to loading scikit-learn? Thanks for the help!
System Parameters
Windows 10
Anaconda 1.9.7
scikit-learn 0.21.3
Tried:
Uninstalling and resintalling scikit-learn with conda
Uninstalling and reinstalling Anaconda distribution
loading the specific item that seems to be issue with from sklearn.base import BaseEstimator
running library in Jupyter Notebook, Microsoft VS Code, and Spyder
Code Entered: from sklearn import linear_model
Error Message:
ImportError Traceback (most recent call last)
<ipython-input-1-b94db01ee140> in <module>
----> 1 from sklearn import linear_model
C:\Util\Anaconda3\lib\site-packages\sklearn\__init__.py in <module>
74 else:
75 from . import __check_build
---> 76 from .base import clone
77 from .utils._show_versions import show_versions
78
C:\Util\Anaconda3\lib\site-packages\sklearn\base.py in <module>
14
15 from . import __version__
---> 16 from .utils import _IS_32BIT
17
18 _DEFAULT_TAGS = {
C:\Util\Anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>
18 from ..exceptions import DataConversionWarning
19 from .deprecation import deprecated
---> 20 from .validation import (as_float_array,
21 assert_all_finite,
22 check_random_state, column_or_1d, check_array,
C:\Util\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <module>
19 from numpy.core.numeric import ComplexWarning
20
---> 21 from .fixes import _object_dtype_isnan
22 from .. import get_config as _get_config
23 from ..exceptions import NonBLASDotWarning
C:\Util\Anaconda3\lib\site-packages\sklearn\utils\fixes.py in <module>
16 import scipy.sparse as sp
17 import scipy
---> 18 from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
19
20
C:\Util\Anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py in <module>
114 from .dsolve import *
115 from .interface import *
--> 116 from .eigen import *
117 from .matfuncs import *
118 from ._onenormest import *
C:\Util\Anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py in <module>
9 from __future__ import division, print_function, absolute_import
10
---> 11 from .arpack import *
12 from .lobpcg import *
13
C:\Util\Anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py in <module>
----> 1 from sklearn.base import BaseEstimator
ImportError: cannot import name 'BaseEstimator' from 'sklearn.base' (C:\Util\Anaconda3\lib\site-packages\sklearn\base.py)

unable to import pandas in jupyter

When I import pandas in jupyter library the following is generated.
AttributeError Traceback (most recent call last)
<ipython-input-24-f869c0f42cc0> in <module>
----> 1 import pandas as pd
2 import numpy as np
3 get_ipython().run_line_magic('matplotlib', 'inline')
C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py in <module>
24
25 try:
---> 26 from pandas._libs import (hashtable as _hashtable,
27 lib as _lib,
28 tslib as _tslib)
pandas\_libs\hashtable_class_helper.pxi in init pandas._libs.hashtable()
AttributeError: type object 'pandas._libs.hashtable.HashTable' has no attribute '__reduce_cython__'
Can you help me in figuring out the problem? Thanks
Use pd at the place of pandas in your code. If you still get error, then write your code also in the question.

OSError: [WinError 126] The specified module could not be found in Python

I am trying to import the following libraries. I get an error message while importing sklearn . I believe it is related to DLL path but i am not able to rectify it . I don't want to manually specify any path in the code. Please help
Code :
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import preprocessing
%matplotlib inline
Error :
OSError Traceback (most recent call last)
<ipython-input-3-c2a7628c052c> in <module>
3 import matplotlib.pyplot as plt
4
----> 5 from sklearn import preprocessing
6 get_ipython().run_line_magic('matplotlib', 'inline')
~\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
62 else:
63 from . import __check_build
---> 64 from .base import clone
65 from .utils._show_versions import show_versions
66
~\anaconda3\lib\site-packages\sklearn\base.py in <module>
10
11 import numpy as np
---> 12 from scipy import sparse
13 from .externals import six
14 from .utils.fixes import signature
~\anaconda3\lib\site-packages\scipy\__init__.py in <module>
102
103 # Allow distributors to run custom init code
--> 104 from . import _distributor_init
105
106 __all__ += _num.__all__
~\anaconda3\lib\site-packages\scipy\_distributor_init.py in <module>
59 os.chdir(libs_path)
60 for filename in glob.glob(os.path.join(libs_path, '*dll')):
---> 61 WinDLL(os.path.abspath(filename))
62 finally:
63 os.chdir(owd)
~\anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
362
363 if handle is None:
--> 364 self._handle = _dlopen(self._name, mode)
365 else:
366 self._handle = handle
OSError: [WinError 126] The specified module could not be found
You can try uninstalling scipy and then re-installing this particular verison. As it is stated in this particular github issue thread that there is a problem with the new release of scipy.
pip uninstall scipy
pip install scipy==1.4.1
https://github.com/ultralytics/yolov5/issues/241

error when import Eof module (udunits error, os error)

from eofs.standard import Eof
i got the error when i import Eof.
This is the error:
UdunitsError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\cf_units\__init__.py in <module>
188 try:
--> 189 _ud_system = _ud.read_xml()
190 except _ud.UdunitsError:
cf_units/_udunits2.pyx in cf_units._udunits2.read_xml()
cf_units/_udunits2.pyx in cf_units._udunits2.wrap_system()
cf_units/_udunits2.pyx in cf_units._udunits2._raise_error()
UdunitsError: UT_OPEN_DEFAULT: b'No such file or directory'
During handling of the above exception, another exception occurred:
UdunitsError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\cf_units\__init__.py in <module>
195 try:
--> 196 _ud_system = _ud.read_xml(_alt_xml_path.encode())
197 except _ud.UdunitsError as e:
cf_units/_udunits2.pyx in cf_units._udunits2.read_xml()
cf_units/_udunits2.pyx in cf_units._udunits2.wrap_system()
cf_units/_udunits2.pyx in cf_units._udunits2._raise_error()
UdunitsError: UT_OPEN_ARG: b'No such file or directory'
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-4-59a1f1d00c07> in <module>
14 import matplotlib.pyplot as plt
15 from mpl_toolkits.basemap import Basemap
---> 16 from eofs.standard import Eof
~\Anaconda3\lib\site-packages\eofs\__init__.py in <module>
19
20 from . import standard
---> 21 from . import tools
22
23 from ._version import get_versions
~\Anaconda3\lib\site-packages\eofs\tools\__init__.py in <module>
32
33 try:
---> 34 from . import iris
35 __all__.append('iris')
36 except ImportError:
~\Anaconda3\lib\site-packages\eofs\tools\iris.py in <module>
22
23 import numpy as np
---> 24 from iris.cube import Cube
25 from iris.analysis.cartography import area_weights
26 from iris.analysis.cartography import cosine_latitude_weights
~\Anaconda3\lib\site-packages\iris\__init__.py in <module>
108
109 import iris.config
--> 110 import iris.cube
111 import iris._constraints
112 from iris._deprecation import IrisDeprecation, warn_deprecated
~\Anaconda3\lib\site-packages\iris\cube.py in <module>
51 import numpy.ma as ma
52
---> 53 from iris._cube_coord_common import CFVariableMixin
54 import iris._concatenate
55 import iris._constraints
~\Anaconda3\lib\site-packages\iris\_cube_coord_common.py in <module>
25 import string
26
---> 27 import cf_units
28
29 import iris.std_names
~\Anaconda3\lib\site-packages\cf_units\__init__.py in <module>
199 raise OSError(
200 '[%s] Failed to open UDUNITS-2 XML unit database%s'
--> 201 % (e.status_msg(), error_msg))
202
203
OSError: [UT_OPEN_ARG] Failed to open UDUNITS-2 XML unit database: "b'No such file or directory'"
could you help me,please?
I have met the same problem and I just fixed it!
Find where your Anaconda3 files are located (path on my computer is C:\Users\asus\Anaconda3).
Find and open the folder named "Library", find and open the folder "share" inside the "Library" (path on my computer is C:\Users\asus\Anaconda3\Library\share).
Inside "share", you have the folder "udunits2" if you have completed the installation of all requirements packages (path in my computer is C:\Users\asus\Anaconda3\Library\share\udunits).
Copy the folder "udunits2".
Go back to C:\Users\asus\Anaconda3.
Important: Find the folder "share" in the current directory (path on my computer is C:\Users\asus\Anaconda3\share).
Paste the "udunits2" into this "share" folder.
Explanation:
So there are two "share" folders in Anaconda. When you import eofs, the cf_units package is using the path C:\Users\asus\Anaconda3\share
However, the file "UDUNITS-2 XML" locates in C:\Users\asus\Anaconda3\Library\share\udunits
You may open the init.py to have a look.
After I copy the "udunits" folder to C:\Users\asus\Anaconda3\share, files are able to be found.
Try to import eofs again!

Assertion Errors while importing Keras modules

I installed Keras using Pip and when I am trying to import modules from Keras, it gives me an assertion error on utils and init modules.
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-48-eda57b582878> in <module>()
----> 1 from keras.callbacks import LambdaCallback
C:\ProgramData\Anaconda3\lib\site-packages\keras\__init__.py in <module>()
1 from __future__ import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications
C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\__init__.py in <module>()
4 from . import data_utils
5 from . import io_utils
----> 6 from . import conv_utils
7
8 # Globally-importable utils.
C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\conv_utils.py in <module>()
7 from six.moves import range
8 import numpy as np
----> 9 from .. import backend as K
10
11
C:\ProgramData\Anaconda3\lib\site-packages\keras\backend\__init__.py in <module>()
34 assert isinstance(_epsilon, float)
35 _backend = _config.get('backend', _BACKEND)
---> 36 assert _backend in {'theano', 'tensorflow', 'cntk'}
37 _image_data_format = _config.get('image_data_format',
38 image_data_format())
AssertionError:
I found a similar question in SOF and checked
python -c "from keras import backend"
in cmd prompt and it gives me the following error.
C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
from . import conv_utils
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
from .. import backend as K
File "C:\ProgramData\Anaconda3\lib\site-
packages\keras\backend\__init__.py", line 36, in <module>
assert _backend in {'theano', 'tensorflow', 'cntk'}
AssertionError
Keras.json:
{
"image_dim_ordering": "tf",
"backend": "mxnet",
"epsilon": 1e-07,
"floatx": "float32"
}
What should I be changing in these modules to avoid this error?
Thanks in Advance.
Based on your update with the contents of your keras.json file, it appears you have set the backend to "mxnet", but this is not a permitted backend of Keras.
Change this value to one of "tensorflow", "theano", or "cntk" and be sure you have that corresponding package also installed. Save the file and try again.

Categories