Background
I'm trying to work on a GAN neural network (I'm a beginner for both Python and Machine-Learning), and I need Tensorflow.
Problem
I have tried to use TensorFlow but can't install. I have read questions and answers on SO about various errors, and have tested out those solutions, but I believe this case is different.
What I have tried (in chronological order)
1. Plain Reboot
a) Close all tabs for Jupyter Notebook
b) Close Anaconda Navigator
c) Restart Jupyter Notebook
d) Rerun code
Result: ImportError: no module
2. Reinstall tf
a) Repeat 1a and 1b
b) Open Anaconda Prompt
c) pip install tensorflow
Result: module installed
3. Check out Navigator
Tensorflow installed in all environments I have.
4. Reinstall tf (Take 2)
a) Repeat 1a and 1b
b) Open Anaconda Prompt
c) conda install -c conda-forge tensorflow
Result: EnvironmentNotWritableError:The current user does not have write permissions to the target environment. environment location: C:\ProgramData\<my username>
5. Run as admin (from this question)
a) Repeat 1a and 1b
b) Open Anaconda Prompt
c) conda install -c conda-forge tensorflow
Result:
Preparing transaction: done
Verifying transaction: done
Executing transaction: <after some text> done
6. Run in Jupyter
The code has nothing to do with TF at the moment, but still, it doesn't work.
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import os
import glob2
font_lib = glob2.glob('**/*.ttf', recursive=True)
count = 0
for f in font_lib:
count = count + 1
if count < 10:
print (f)
else:
break
print ("done")
Result:
AttributeError Traceback (most recent call last)
<ipython-input-6-efbffb1990be> in <module>
----> 1 import tensorflow as tf
2 import numpy as np
3 import matplotlib.pyplot as plt
4 import os
5 import glob2
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
22
23 # pylint: disable=g-bad-import-order
---> 24 from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
25
26 from tensorflow._api.v1 import app
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
80 from tensorflow.python import data
81 from tensorflow.python import distribute
---> 82 from tensorflow.python import keras
83 from tensorflow.python.feature_column import feature_column_lib as feature_column
84 from tensorflow.python.layers import layers
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\__init__.py in <module>
23
24 from tensorflow.python.keras import activations
---> 25 from tensorflow.python.keras import applications
26 from tensorflow.python.keras import backend
27 from tensorflow.python.keras import callbacks
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\applications\__init__.py in <module>
24 from tensorflow.python.keras import backend
25 from tensorflow.python.keras import engine
---> 26 from tensorflow.python.keras import layers
27 from tensorflow.python.keras import models
28 from tensorflow.python.keras import utils
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\__init__.py in <module>
27
28 # Advanced activations.
---> 29 from tensorflow.python.keras.layers.advanced_activations import LeakyReLU
30 from tensorflow.python.keras.layers.advanced_activations import PReLU
31 from tensorflow.python.keras.layers.advanced_activations import ELU
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\advanced_activations.py in <module>
25 from tensorflow.python.keras.engine.base_layer import Layer
26 from tensorflow.python.keras.engine.input_spec import InputSpec
---> 27 from tensorflow.python.keras.utils import tf_utils
28 from tensorflow.python.ops import math_ops
29 from tensorflow.python.util.tf_export import tf_export
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\__init__.py in <module>
36 from tensorflow.python.keras.utils.layer_utils import get_source_inputs
37 from tensorflow.python.keras.utils.losses_utils import squeeze_or_expand_dimensions
---> 38 from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
39 from tensorflow.python.keras.utils.np_utils import normalize
40 from tensorflow.python.keras.utils.np_utils import to_categorical
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\multi_gpu_utils.py in <module>
20 from tensorflow.python.framework import ops
21 from tensorflow.python.keras import backend as K
---> 22 from tensorflow.python.keras.engine.training import Model
23 from tensorflow.python.ops import array_ops
24 from tensorflow.python.util.tf_export import tf_export
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in <module>
40 from tensorflow.python.keras.engine import training_generator
41 from tensorflow.python.keras.engine import training_utils
---> 42 from tensorflow.python.keras.engine.network import Network
43 from tensorflow.python.keras.optimizer_v2 import optimizer_v2
44 from tensorflow.python.keras.utils import data_utils
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\network.py in <module>
38 from tensorflow.python.keras.engine import base_layer
39 from tensorflow.python.keras.engine import base_layer_utils
---> 40 from tensorflow.python.keras.engine import saving
41 from tensorflow.python.keras.engine import training_utils
42 from tensorflow.python.keras.utils import generic_utils
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\saving.py in <module>
36 # pylint: disable=g-import-not-at-top
37 try:
---> 38 import h5py
39 HDF5_OBJECT_HEADER_LIMIT = 64512
40 except ImportError:
C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py in <module>
34 _errors.silence_errors()
35
---> 36 from ._conv import register_converters as _register_converters
37 _register_converters()
38
h5py\h5r.pxd in init h5py._conv()
h5py\h5r.pyx in init h5py.h5r()
AttributeError: type object 'h5py.h5r.Reference' has no attribute '__reduce_cython__'
7. Update h5py
a) Followed #Alireza Tajadod's instructions and tried.
b) Run code in Jupyter
Result: Same as 6)...
I have tried every method I could, and any help would be highly appreciated. Thank you in advance!
Edit:
Reminded by the answer by #GarytheIceBreaker: Sorry that I forgot to mention, but I have everything installed and set up in Windows. Although this might be frustrating to some, please suggest solutions that can be done within Windows OS premises. Thanks!
I tried jumping through hoops on Windows, and did get Anaconda working, but not Tensorflow. I recommend running Ubuntu virtually, on WSL if you don't want to make any major changes to your machine. Ubuntu is pretty user friendly these days, even if you use it without any graphical shell enabled.
Enable WSL, install Ubuntu from the Microsoft store, and apt-get install tensorflow.
Related
Getting error, ModuleNotFoundError: No module named 'tensorflow.python.util
I've tried uninstalling and reinstalling more than 10 times, and tried different variations
pip install tensorflow_gpu, pip install tensorflow --user, and also upgraded my pip.
But still this error keeps happening when I try to import keras.models from tensorflow to run a model.
Does anyone know how to resolve the issue? Thanks in advance.
The full error I am getting:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-67-114c1607a26b> in <module>
4 from datetime import datetime
5 import numpy as np
----> 6 from tensorflow import keras
7 from keras.models import Sequential
8 from keras.layers import LSTM
~\AppData\Roaming\Python\Python38\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
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\__init__.py in <module>
38 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
39
---> 40 from tensorflow.python.eager import context
41 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
42
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\context.py in <module>
34 from tensorflow.core.protobuf import rewriter_config_pb2
35 from tensorflow.python import pywrap_tfe
---> 36 from tensorflow.python import tf2
37 from tensorflow.python.client import pywrap_tf_session
38 from tensorflow.python.eager import executor
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\tf2.py in <module>
24
25 from tensorflow.python.platform import _pywrap_tf2
---> 26 from tensorflow.python.util.tf_export import tf_export
27
28
ModuleNotFoundError: No module named 'tensorflow.python.util
My guess is that pip is installing it for python 2 and then you are running in python 3. I have seen this behaviour and then needing to use pip3.
import pandas
from sklearn import tree
import pydotplus
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
import matplotlib.image as pltimg
dtree = DecisionTreeClassifier()
dtree = dtree.fit(X, y)
y_pred = dtree.predict(X)
y_pred
The error ::
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-33-745bbfa9769b> in <module>
1 import pandas
----> 2 from sklearn import tree
3 import pydotplus
4 from sklearn.tree import DecisionTreeClassifier
5 import matplotlib.pyplot as plt
~/opt/anaconda3/lib/python3.8/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
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/base.py in <module>
12 from scipy import sparse
13 from .externals import six
---> 14 from .utils.fixes import signature
15 from .utils import _IS_32BIT
16 from . import __version__
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/utils/__init__.py in <module>
12 from .murmurhash import murmurhash3_32
13 from .class_weight import compute_class_weight, compute_sample_weight
---> 14 from . import _joblib
15 from ..exceptions import DataConversionWarning
16 from .fixes import _Sequence as Sequence
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/utils/_joblib.py in <module>
20 from joblib import parallel_backend, register_parallel_backend
21 else:
---> 22 from ..externals import joblib
23 from ..externals.joblib import logger
24 from ..externals.joblib import dump, load
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/__init__.py in <module>
117 from .numpy_pickle import load
118 from .compressor import register_compressor
--> 119 from .parallel import Parallel
120 from .parallel import delayed
121 from .parallel import cpu_count
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/parallel.py in <module>
26 from .my_exceptions import TransportableException
27 from .disk import memstr_to_bytes
---> 28 from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
29 ThreadingBackend, SequentialBackend,
30 LokyBackend)
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/_parallel_backends.py in <module>
20 from .pool import MemmappingPool
21 from multiprocessing.pool import ThreadPool
---> 22 from .executor import get_memmapping_executor
23
24 # Compat between concurrent.futures and multiprocessing TimeoutError
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/executor.py in <module>
12 from .disk import delete_folder
13 from ._memmapping_reducer import get_memmapping_reducers
---> 14 from .externals.loky.reusable_executor import get_reusable_executor
15
16
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/externals/loky/__init__.py in <module>
10
11 from .backend.context import cpu_count
---> 12 from .backend.reduction import set_loky_pickler
13 from .reusable_executor import get_reusable_executor
14 from .cloudpickle_wrapper import wrap_non_picklable_objects
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/externals/loky/backend/reduction.py in <module>
123 # global variable to change the pickler behavior
124 try:
--> 125 from sklearn.externals.joblib.externals import cloudpickle # noqa: F401
126 DEFAULT_ENV = "cloudpickle"
127 except ImportError:
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/__init__.py in <module>
1 from __future__ import absolute_import
2
----> 3 from .cloudpickle import *
4
5 __version__ = '0.6.1'
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py in <module>
165
166
--> 167 _cell_set_template_code = _make_cell_set_template_code()
168
169
~/opt/anaconda3/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py in _make_cell_set_template_code()
146 )
147 else:
--> 148 return types.CodeType(
149 co.co_argcount,
150 co.co_kwonlyargcount,
TypeError: an integer is required (got type bytes)
So I keep getting this type error and have no clue what to do pretty sure that sklearn is installed. Both X and y are previously defined after creating the training set to be used. I've tried reinstalling scikit-learn, downgrading python and installing through the terminal but none of that helped. Just cant figure out what the issue is here and will really appreciate some help on this
I was able to reproduce the problem in a conda environment by running conda install python==3.8 scikit-learn but then manually downgrading joblib by running pip install joblib<0.14 since joblib<0.14 is incompatible with Python 3.8.
I'm not exactly sure how you got into the this situation, but it should fix it to first uninstall any joblib package that might have been mis-installed:
$ pip uninstall joblib
Then force reinstall/upgrade it with conda:
$ conda update --force-reinstall joblib
Confirm the correct version was installed:
$ python -c 'import joblib; print(joblib.__version__)'
0.17.0
If all else fails, try creating a fresh Anaconda install. Make sure to install packages with conda install and not pip.
In my case, joblib in scikit needs to be reinstalled.
pip uninstall joblib
This happened to me because I pip installed sklearn instead of scikit-learn.
In my case, I did
pip uninstall sklearn --yes
followed by
pip install sklearn
Getting this error when trying to import tf_agents.environments running on Tensorflow 2.3.0, using anaconda environment. Have tried to reinstall tensorflow, still getting same error. Running the jupyter notebook in as admin, still getting same error. I am using python 3.8
from tf_agents.environments import suite_gym
ImportError Traceback (most recent call last)
<ipython-input-8-b9cd8ac2787f> in <module>
----> 1 from tf_agents.environments import suite_gym
2
3 # env = suite_gym.load("Breakout-v4")
4 # env
~\AppData\Roaming\Python\Python38\site-packages\tf_agents\environments\__init__.py in <module>
24 from tf_agents.environments import tf_py_environment
25 from tf_agents.environments import trajectory_replay
---> 26 from tf_agents.environments import utils
27 from tf_agents.environments import wrappers
~\AppData\Roaming\Python\Python38\site-packages\tf_agents\environments\utils.py in <module>
23 from tf_agents.environments import tf_environment
24 from tf_agents.environments import tf_py_environment
---> 25 from tf_agents.policies import random_py_policy
26 from tf_agents.specs import array_spec
27
~\AppData\Roaming\Python\Python38\site-packages\tf_agents\policies\__init__.py in <module>
16 """Policies Module."""
17
---> 18 from tf_agents.policies import actor_policy
19 from tf_agents.policies import boltzmann_policy
20 from tf_agents.policies import epsilon_greedy_policy
~\AppData\Roaming\Python\Python38\site-packages\tf_agents\policies\actor_policy.py in <module>
27 import tensorflow_probability as tfp
28
---> 29 from tf_agents.networks import network
30 from tf_agents.policies import tf_policy
31 from tf_agents.specs import tensor_spec
~\AppData\Roaming\Python\Python38\site-packages\tf_agents\networks\__init__.py in <module>
16 """Networks Module."""
17
---> 18 from tf_agents.networks import actor_distribution_network
19 from tf_agents.networks import actor_distribution_rnn_network
20 from tf_agents.networks import bias_layer
~\AppData\Roaming\Python\Python38\site-packages\tf_agents\networks\actor_distribution_network.py in <module>
24 import tensorflow as tf # pylint: disable=g-explicit-tensorflow-version-import
25
---> 26 from tf_agents.networks import categorical_projection_network
27 from tf_agents.networks import encoding_network
28 from tf_agents.networks import network
~\AppData\Roaming\Python\Python38\site-packages\tf_agents\networks\categorical_projection_network.py in <module>
24 import tensorflow_probability as tfp
25
---> 26 from tf_agents.networks import network
27 from tf_agents.networks import utils
28 from tf_agents.specs import distribution_spec
~\AppData\Roaming\Python\Python38\site-packages\tf_agents\networks\network.py in <module>
31
32 # pylint:disable=g-direct-tensorflow-import
---> 33 from tensorflow.python.keras.engine import network as keras_network # TF internal
34 from tensorflow.python.training.tracking import base # TF internal
35 from tensorflow.python.util import tf_decorator # TF internal
ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine' (C:\Users\Vision\anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\__init__.py)
Am a bit late here, but faced a similar issue.
How I resolved the issue :
Uninstall the current version of tf_agents, use
pip uninstall tf-agents
Please install the current tf-agents-nightly (0.6.0) GitHub Repo.
use pip install tf-agents-nightly
from tf_agents.environments import suite_gym
I was using this code:
import tensorflow as tf , and it was working fine.
When I now try to import it, I get the following error
In [2]: import tensorflow as tf
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-41389fad42b5> in <module>()
----> 1 import tensorflow as tf
/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py in <module>()
21 from __future__ import print_function
22
---> 23 from tensorflow.python import *
/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py in <module>()
63 from tensorflow.core.util.event_pb2 import *
64 # Import things out of contrib
---> 65 import tensorflow.contrib as contrib
66
67 # Framework
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/__init__.py in <module>()
28 from tensorflow.contrib import grid_rnn
29 from tensorflow.contrib import layers
---> 30 from tensorflow.contrib import learn
31 from tensorflow.contrib import linear_optimizer
32 from tensorflow.contrib import lookup
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/__init__.py in <module>()
70
71 # pylint: disable=wildcard-import
---> 72 from tensorflow.contrib.learn.python.learn import *
73 from tensorflow.python.util.all_util import make_all
74
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/__init__.py in <module>()
21
22 # pylint: disable=wildcard-import
---> 23 from tensorflow.contrib.learn.python.learn import *
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/__init__.py in <module>()
24 # pylint: disable=wildcard-import
25 from tensorflow.contrib.learn.python.learn import datasets
---> 26 from tensorflow.contrib.learn.python.learn import estimators
27 from tensorflow.contrib.learn.python.learn import graph_actions
28 from tensorflow.contrib.learn.python.learn import learn_io as io
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/__init__.py in <module>()
21
22 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
---> 23 from tensorflow.contrib.learn.python.learn.estimators.autoencoder import TensorFlowDNNAutoencoder
24 from tensorflow.contrib.learn.python.learn.estimators.base import TensorFlowBaseTransformer
25 from tensorflow.contrib.learn.python.learn.estimators.base import TensorFlowEstimator
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/autoencoder.py in <module>()
23
24 from tensorflow.contrib.learn.python.learn import models
---> 25 from tensorflow.contrib.learn.python.learn.estimators.base import TensorFlowBaseTransformer
26 from tensorflow.python.ops import nn
27
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/base.py in <module>()
32 from tensorflow.contrib import layers
33 from tensorflow.contrib.learn.python.learn.estimators import _sklearn
---> 34 from tensorflow.contrib.learn.python.learn.estimators import estimator
35 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
36 from tensorflow.contrib.learn.python.learn.learn_io.data_feeder import setup_train_data_feeder
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py in <module>()
37 from tensorflow.contrib.learn.python.learn.estimators import tensor_signature
38 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
---> 39 from tensorflow.contrib.learn.python.learn.learn_io import data_feeder
40 from tensorflow.contrib.learn.python.learn.utils import checkpoints
41
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/learn_io/__init__.py in <module>()
28 from tensorflow.contrib.learn.python.learn.learn_io.graph_io import read_keyed_batch_examples
29 from tensorflow.contrib.learn.python.learn.learn_io.graph_io import read_keyed_batch_features
---> 30 from tensorflow.contrib.learn.python.learn.learn_io.pandas_io import extract_pandas_data
31 from tensorflow.contrib.learn.python.learn.learn_io.pandas_io import extract_pandas_labels
32 from tensorflow.contrib.learn.python.learn.learn_io.pandas_io import extract_pandas_matrix
/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/learn_io/pandas_io.py in <module>()
22 try:
23 # pylint: disable=g-import-not-at-top
---> 24 import pandas as pd
25 HAS_PANDAS = True
26 except ImportError:
/usr/local/lib/python2.7/dist-packages/pandas/__init__.py in <module>()
23
24 try:
---> 25 from pandas import hashtable, tslib, lib
26 except ImportError as e: # pragma: no cover
27 module = str(e).lstrip('cannot import name ') # hack but overkill to use re
/home/kv/pandas/src/numpy.pxd in init pandas.hashtable (pandas/hashtable.c:38364)()
ValueError: numpy.dtype has the wrong size, try recompiling. Expected 88, got 96
I even tried upgrading numpy, but that didn't solve the issue.
Can you help me resolve this error?
EDIT:
numpy (1.8.2)
tensorflow (0.10.0rc0)
python 2.7.6
You need to update numpy or recompile pandas.
There is a very good answer and explanation provided here: ValueError: numpy.dtype has the wrong size, try recompiling
I would strongly suggest to use the anaconda distribution and install the latest tensorflow using:
conda install -c conda-forge tensorflow
Read more in the official setup guide
Try installing numpy with PIP using
sudo apt-get install python-pip
sudo pip install numpy==1.11.1
or pip3 instead of pip for python 3 like
sudo apt-get install python3-pip
sudo pip3 install numpy==1.11.1
this will help as i also had this error because tensorflow is using numpy 1.11.1
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.)