ImportError: No module named src.utils tensorflow - python

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

Related

ImportError loading spacy in jupyter notebook(ubuntu)

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)

ImportError: cannot import name 'safe_indexing' from 'sklearn.utils'

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.

import fancyimpute Runtime and ImportError

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.

How to import TimeSeriesNet() from nnet-ts in mac ox?

I have installed nnet-ts in mac using
pip install nnet-ts
All the dependency libraries are already installed. But while importing module nnet_ts
from nnet_ts import *
following error is generated
ModuleNotFoundError Traceback (most recent
call last)
<ipython-input-7-ad5e84de7763> in <module>
----> 1 from nnet_ts import *
2 count=0
3 ahead=12
4 pred=[]
~/anaconda3/lib/python3.6/site-packages/nnet_ts/__init__.py in <module>
5 from keras.layers.core import Dense, Activation, Dropout
6 from sklearn.preprocessing import StandardScaler
----> 7 from TimeSeriesNnet import TimeSeriesNnet
ModuleNotFoundError: No module named 'TimeSeriesNnet'
I try to figure out from this thread Using the TimeSeriesNnet() method from the nnet_ts module throws NameError
but does not work for MAC. How can we solve this problem in MAC OX?

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.

Categories

Resources