Scikitlearn in Jupyter notebook using Anaconda - python

This is not a duplicate because the linked question does not address how to either locate the required dlls or fix the installation.
I get the following when I try import sklearn v.0.20. I'm using anaconda and both numpy and scipy are up to date.
ImportError Traceback (most recent call last)
<ipython-input-1-8fd979e02004> in <module>()
----> 1 import sklearn
C:\Users\James2SxyBoogaloo\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
C:\Users\James2SxyBoogaloo\Anaconda3\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\James2SxyBoogaloo\Anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>()
11
12 from .murmurhash import murmurhash3_32
---> 13 from .validation import (as_float_array,
14 assert_all_finite,
15 check_random_state, column_or_1d, check_array,
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <module>()
20
21 from ..externals import six
---> 22 from ..utils.fixes import signature
23 from .. import get_config as _get_config
24 from ..exceptions import NonBLASDotWarning
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\sklearn\utils\fixes.py in <module>()
81 return stats.boxcox(x, lmbda)
82 else:
---> 83 from scipy.special import boxcox # noqa
84
85
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\scipy\special\__init__.py in <module>()
638 from .sf_error import SpecialFunctionWarning, SpecialFunctionError
639
--> 640 from ._ufuncs import *
641
642 from .basic import *
ImportError: DLL load failed: The specified module could not be found.

EDIT:
I found this thread : https://github.com/numpy/numpy/issues/10965
That mentions a problem related to this.
So it seems the guy there solved his problem by removing both numpy and scipy and reinstalling them. There is a chance your version of scipy for some reason is linked against a MLK version of numpy and that's the reason things don't work.
END OF EDIT
I checked around for your problem and it seems that this is related to the version of numpy you have.
To fix the problem you should install numpy-MLK which is a version on numpy linked against Intel's Math Kernel Library.
You can find it here:
https://pypi.org/project/numpy-mkl/
Just remember to first remove the already existing numpy package.
You can find more info here:
ImportError when importing certain modules from SciPY
and here:
Difference between Numpy and Numpy-MKL?

Related

Cannot import tensorflow after a week of no use, no changes was made

What I've did:
uninstall and pip install tensorflow-macos
uninstall pip install tensorflow-metal
import tensorflow as tf
The expected result is no error.
However, I got an error after importing tensorflow.
TypeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import tensorflow as tf
3 # from keras import datasets, layers, models
4 # import matplotlib.pyplot as plt
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/__init__.py:37
34 import sys as _sys
35 import typing as _typing
---> 37 from tensorflow.python.tools import module_util as _module_util
38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
40 # Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/__init__.py:45
43 from tensorflow.python import distribute
44 # from tensorflow.python import keras
---> 45 from tensorflow.python.feature_column import feature_column_lib as feature_column
46 # from tensorflow.python.layers import layers
47 from tensorflow.python.module import module
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/feature_column/feature_column_lib.py:18
15 """FeatureColumns: tools for ingesting and representing features."""
17 # pylint: disable=unused-import,line-too-long,wildcard-import,g-bad-import-order
---> 18 from tensorflow.python.feature_column.feature_column import *
...
(...)
3248 :returns: The PKCS12 object
3249 """
TypeError: deprecated() got an unexpected keyword argument 'name'

ModelicaRes import fails in python

I want to use ModelicaRes to open my Dymola results in python but the import fails.
from modelicares.simres import SimRes
Gives the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In [2], line 1
----> 1 from modelicares.simres import SimRes
File C:\ProgramData\Miniforge3\envs\main\lib\site-packages\modelicares\__init__.py:54
40 __version__ = '0.12.2'
43 # Standard pylint settings for this project:
44 # pylint: disable=I0011, C0302, C0325, R0903, R0904, R0912, R0913, R0914, R0915,
45 # pylint: disable=I0011, W0141, W0142
(...)
52 # These will be available directly from modelicares; others must be loaded from
53 # their submodules.
---> 54 from modelicares.simres import SimRes, SimResList
55 from modelicares.linres import LinRes, LinResList
56 from modelicares.util import (add_arrows, add_hlines, add_vlines, ArrowLine,
57 closeall, multiglob, figure, load_csv, save,
58 saveall, setup_subplots)
File C:\ProgramData\Miniforge3\envs\main\lib\site-packages\modelicares\simres.py:50
48 from itertools import cycle
49 from matplotlib import rcParams
---> 50 from matplotlib.cbook import iterable
51 from matplotlib.pyplot import figlegend
52 from pandas import DataFrame
ImportError: cannot import name 'iterable' from 'matplotlib.cbook' (C:\ProgramData\Miniforge3\envs\main\lib\site-packages\matplotlib\cbook\__init__.py)
I tried DyMat and Buildingspy but I would prefer to use ModelicaRes. Because Buildingspy makes use of DyMat which is quiet old and seems unmaintained.
I also had this issue.
I fixed this in my fork of modelicares here: https://github.com/sede-fa/ModelicaRes
I basically replaced any reference to matplotlib.cbook to numpy to get the iterable function as shown here: https://github.com/kdavies4/ModelicaRes/issues/42
You can install this via pip by doing: pip install git+https://github.com/sede-fa/ModelicaRes.git

ModuleNotFoundError: No module named 'numpy.testing.decorators'

I really need some help, as I have gone through all the posts and nothing has worked. I get this error when importing gensim and not numpy (numpy is before and works fine). All I want to do is import gensim and numpy to then run my analysis.
Here is the full error message:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-3f0b98039a34> in <module>()
1 # pip install --user numpy==1.16.4
2
----> 3 import gensim
4 #import numpy
5
~/.local/lib64/python3.6/site-packages/gensim/__init__.py in <module>()
9 import logging
10
---> 11 from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils # noqa:F401
12
13
~/.local/lib64/python3.6/site-packages/gensim/corpora/__init__.py in <module>()
4
5 # bring corpus classes directly into package namespace, to save some typing
----> 6 from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes
7
8 from .mmcorpus import MmCorpus # noqa:F401
~/.local/lib64/python3.6/site-packages/gensim/corpora/indexedcorpus.py in <module>()
12 import numpy
13
---> 14 from gensim import interfaces, utils
15
16 logger = logging.getLogger(__name__)
~/.local/lib64/python3.6/site-packages/gensim/interfaces.py in <module>()
17 import logging
18
---> 19 from gensim import utils, matutils
20
21
~/.local/lib64/python3.6/site-packages/gensim/matutils.py in <module>()
17 import numpy as np
18 import scipy.sparse
---> 19 from scipy.stats import entropy
20 import scipy.linalg
21 from scipy.linalg.lapack import get_lapack_funcs
/cluster/apps/python/3.6.4_cpu/lib64/python3.6/site-packages/scipy/stats/__init__.py in <module>()
343 from .stats import *
344 from .distributions import *
--> 345 from .morestats import *
346 from ._binned_statistic import *
347 from .kde import gaussian_kde
/cluster/apps/python/3.6.4_cpu/lib64/python3.6/site-packages/scipy/stats/morestats.py in <module>()
10 sqrt, ceil, floor, array, compress,
11 pi, exp, ravel, count_nonzero, sin, cos, arctan2, hypot)
---> 12 from numpy.testing.decorators import setastest
13
14 from scipy._lib.six import string_types
ModuleNotFoundError: No module named 'numpy.testing.decorators'
What I have tried:
I have tried using the latest version of numpy, and also forcing it to the version 1.16.4 "pip install --user numpy==1.16.4". I have also tried uninstalling and reinstalling both gensim and numpy, but its not working. I am using Python 3.6 and on a cluster. I don't really understand why numpy has no problem being imported, but that this is a problem of gensim.
Can anyone kindly help me out with this?
Thanks a lot!
Best,
Sandra

ImportError: cannot import name 'ClusterDef'

About a week ago I was able to import tensor flow but now I seem to have a problem running the same code. When I run either of these I am not able to get it to work at this point (what surprises me the most is at least part of it worked last week, now it does not seem to work), I get ImportError: cannot import name 'ClusterDef' which I am not finding anything online on:
import tensorflow
import keras
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-a649b509054f> in <module>()
----> 1 import tensorflow
/anaconda3/lib/python3.6/site-packages/tensorflow/__init__.py in <module>()
39 import sys as _sys
40
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43
/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py in <module>()
75
76 # Bring in subpackages.
---> 77 from tensorflow.python.estimator import estimator_lib as estimator
78 from tensorflow.python.layers import layers
79 from tensorflow.python.ops import image_ops as image
/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator_lib.py in <module>()
20
21 # pylint: disable=unused-import,line-too-long
---> 22 from tensorflow.python.estimator.estimator import Estimator
23 from tensorflow.python.estimator.export import export_lib as export
24 from tensorflow.python.estimator.inputs import inputs
/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py in <module>()
48 from tensorflow.python.training import monitored_session
49 from tensorflow.python.training import saver
---> 50 from tensorflow.python.training import training
51 from tensorflow.python.util import compat
52
/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/training.py in <module>()
180
181 # Distributed computing support.
--> 182 from tensorflow.core.protobuf.tensorflow_server_pb2 import ClusterDef
183 from tensorflow.core.protobuf.tensorflow_server_pb2 import JobDef
184 from tensorflow.core.protobuf.tensorflow_server_pb2 import ServerDef
ImportError: cannot import name 'ClusterDef'
There is usually two reasons for ImportError
it's circular import attempt
the target object does not exist
in your case i would check if this file really contains ClusterDef class
/anaconda3/lib/python3.6/site-packages/tensorflow/core/protobuf/tensorflow_server_pb2.py
this is dynamically generated protobuf files (by grpc), which could somehow got deleted
in case this file does not contain needed class the best option is probably reinstall tensorflow/anaconda

h5py errors after installation

I'm trying to install h5py on Mac OSX and use it's group and dataset features, but I'm having an issue. On its installation webpage it says the easiest way for beginners to use it on Mac is to install Anaconda, so that's what I did since I would still consider myself an inexperienced programmer. Anyway, after installing Anaconda and typing the following script into iPython Notebook, I get an "image not found error."
import h5py
import numpy as np
f = h5py.File("mytestfile.hdf5" , "w")
Here is the full error (its pretty long):
ImportError Traceback (most recent call last)
<ipython-input-1-65d72c32bd56> in <module>()
----> 1 import h5py
2 import numpy as np
3
4 f = h5py.File("mytestfile.hdf5", "w")
/Users/wlentzii/anaconda/lib/python2.7/site-packages/h5py/__init__.py in <module>()
21 _errors.silence_errors()
22
---> 23 from . import _conv
24 _conv.register_converters()
25
h5py/h5t.pxd in init h5py._conv (-------src-dir--------/h5py/_conv.c:6961)()
h5py/numpy.pxd in init h5py.h5t (-------src-dir--------/h5py/h5t.c:19623)()
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site- packages/numpy/__init__.pyc in <module>()
166 return loader(*packages, **options)
167
--> 168 from . import add_newdocs
169 __all__ = ['add_newdocs', 'ModuleDeprecationWarning']
170
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site- packages/numpy/add_newdocs.py in <module>()
11 from __future__ import division, absolute_import, print_function
12
---> 13 from numpy.lib import add_newdoc
14
15 ###############################################################################
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site- packages/numpy/lib/__init__.py in <module>()
16
17 from . import scimath as emath
---> 18 from .polynomial import *
19 #import convertcode
20 from .utils import *
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/polynomial.py in <module>()
17 from numpy.lib.function_base import trim_zeros, sort_complex
18 from numpy.lib.type_check import iscomplex, real, imag
---> 19 from numpy.linalg import eigvals, lstsq, inv
20
21 class RankWarning(UserWarning):
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/__init__.py in <module>()
48 from .info import __doc__
49
---> 50 from .linalg import *
51
52 from numpy.testing import Tester
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/linalg.py in <module>()
27 )
28 from numpy.lib import triu, asfarray
---> 29 from numpy.linalg import lapack_lite, _umath_linalg
30 from numpy.matrixlib.defmatrix import matrix_power
31 from numpy.compat import asbytes
ImportError: dlopen(/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib /python2.7/site-packages/numpy/linalg/lapack_lite.so, 2): Library not loaded: #rpath/lib/libmkl_intel_lp64.dylib
Referenced from: /Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so
Reason: image not found
Your traceback shows that you are using Canopy's Python, not Anaconda's. Either (1) make sure Anaconda appears in your system path before Canopy or (2) use Canopy's package manager to install h5py. Since you have Canopy installed already, and that's what appears first in your path already, that might be the easiest choice for you. You can either use the graphical Package Manager (reachable from the Welcome screen) or install h5py from the command-line
enpkg h5py

Categories

Resources