Setting up scikit-learn - numpy errors on import - python

I'm trying to set up scikit-learn, but after installing numpy and scikit-learn (using pip) that's what I get when trying to imort sklearn:
import sklearn
RuntimeError: module compiled against API version 8 but this version of numpy is 7
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/sklearn/__init__.py", line 32, in <module>
from .base import clone
File "/usr/local/lib/python2.7/site-packages/sklearn/base.py", line 10, in <module>
from scipy import sparse
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/__init__.py", line 182, in <module>
from .csr import *
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/csr.py", line 15, in <module>
from .sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/sparsetools/__init__.py", line 5, in <module>
from .csr import *
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/sparsetools/csr.py", line 26, in <module>
_csr = swig_import_helper()
File "/Library/Python/2.7/site-packages/scipy-0.13.0.dev_c31f167_20130304-py2.7-macosx-10.8-intel.egg/scipy/sparse/sparsetools/csr.py", line 22, in swig_import_helper
_mod = imp.load_module('_csr', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import
Tried to reinstall things without success

Looking at this issue on github, it sounds like it might require a specific version of numpy - they used 1.7.0b2.

Related

Failed to load the native TensorFlow runtime in Pycharm

This is what I am currently running in the PyCharm Project
Windows 10
PyCharm 2020.1.1 (Community Edition)
Python 3.7.7
TensorFlow 2.2.0
This is what I have in codes in terms of imports:
import math
import pandas_datareader as web
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
Here are the errors......
H:\Python\AI\venv\lib\site-packages\pandas_datareader\compat\__init__.py:7:
FutureWarning: pandas.util.testing is deprecated. Use the functions in
the public API at pandas.testing instead. from pandas.util.testing
import assert_frame_equal Using TensorFlow backend. Traceback (most
recent call last): File
"H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import * File "H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper() File "H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File
"C:\Users\Chan\AppData\Local\Programs\Python\Python37\lib\imp.py",
line 242, in load_module
return load_dynamic(name, filename, file) File "C:\Users\Chan\AppData\Local\Programs\Python\Python37\lib\imp.py",
line 342, in load_dynamic
return _load(spec) ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "H:/Python/AI/LSMT.py", line
7, in <module>
from keras.models import Sequential File "H:\Python\AI\venv\lib\site-packages\keras\__init__.py", line 3, in
<module>
from . import utils File "H:\Python\AI\venv\lib\site-packages\keras\utils\__init__.py", line 6,
in <module>
from . import conv_utils File "H:\Python\AI\venv\lib\site-packages\keras\utils\conv_utils.py", line
9, in <module>
from .. import backend as K File "H:\Python\AI\venv\lib\site-packages\keras\backend\__init__.py", line
1, in <module>
from .load_backend import epsilon File "H:\Python\AI\venv\lib\site-packages\keras\backend\load_backend.py",
line 90, in <module>
from .tensorflow_backend import * File "H:\Python\AI\venv\lib\site-packages\keras\backend\tensorflow_backend.py",
line 5, in <module>
import tensorflow as tf File "H:\Python\AI\venv\lib\site-packages\tensorflow\__init__.py", line 41,
in <module>
from tensorflow.python.tools import module_util as _module_util File
"H:\Python\AI\venv\lib\site-packages\tensorflow\python\__init__.py",
line 50, in <module>
from tensorflow.python import pywrap_tensorflow File "H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 69, in <module>
raise ImportError(msg) ImportError: Traceback (most recent call last): File
"H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import * File "H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper() File "H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File
"C:\Users\Chan\AppData\Local\Programs\Python\Python37\lib\imp.py",
line 242, in load_module
return load_dynamic(name, filename, file) File "C:\Users\Chan\AppData\Local\Programs\Python\Python37\lib\imp.py",
line 342, in load_dynamic
return _load(spec) ImportError: DLL load failed: The specified module could not be found.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Process finished with exit code 1
I have to tried uninstall, re-install, upgrade, change from Python 3.8 to 3.7, ..., but I still get an error.
It was the version issue.
I changed TensorFlow to 1.15, cudart64_100 error showed up.
I then installed CUDA 10.1 with cudart64_101.dll problem still exist.
Then I followed this post....
https://www.joe0.com/2019/10/19/how-resolve-tensorflow-2-0-error-could-not-load-dynamic-library-cudart64_100-dll-dlerror-cudart64_100-dll-not-found/
Downloaded, extracted the cudart64_100.dll provided by the OP....
Reinstalled TensorFlow 2.0.0.
Restarted my computer.
Problem Solved.
Only with the Future Warning; but no big deal. I can now run my program.
\pandas_datareader\compat\__init__.py:7: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
from pandas.util.testing import assert_frame_equal
Using TensorFlow backend.

ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found [duplicate]

This question already has an answer here:
can't import tensorflow in python, windows 10 64 bit
(1 answer)
Closed 2 years ago.
I am trying to make a simple LSTM time-series model for predicting future prices using the past prices. I am getting error while running the code. I have imported keras in my code but I have not imported tensorflow directly. It shows the below error:
Traceback (most recent call last):
File "pricePredictor.py", line 29, in <module>
from keras.models import Sequential
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
from . import conv_utils
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
from .. import backend as K
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\backend\__init__.py", line 1, in <module>
from .load_backend import epsilon
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\backend\load_backend.py", line 90, in <module>
from .tensorflow_backend import *
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Shashank\AppData\Local\Programs\Python\Python38\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Failed to load the native TensorFlow runtime.
I have installed tensorflow, tensorflow-gpu, tensorflow-gpu-estimator. Is there anything left to be installed before using this? Also, I do not have a lot of data for training. I have only past 1 year prices. So can I run my code on CPU if the problem is with GPU?
I have Intel(R) UHD Graphics 620 GPU with approx. memory 4176MB(if it is needed).
To fix DLL load failed error, you have to download and install/update the Microsoft Visual C++ 2015-2019 Redistributable (x64) from here.
If you are still facing any other issues possible reasons are mentioned here

Deep Learning with Python using Tensorflow and Keras on AMD GPU with ROCm gives errors when I run the program below

I have an AMD GPU pc which I have recently started to use with Linux Mint O.S. I've seen a way of installing ROCm on this pc following this tutorial, but when I tried to write a Python program using Keras it threw these errors. Here is my code:
import numpy as np
from numpy import genfromtxt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense
data=genfromtxt('../DATA/bank_note_data.txt',delimiter=',')
labels=data[:,4]
features=data[:,0:4]
X=features
y=labels
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.33,random_state=42)
scalerObject=MinMaxScaler()
scalerObject.fit(X_train)
scaled_X_train=scalerObject.transform(X_train)
scaled_X_test=scalerObject.transform(X_test)
model=Sequential()
model.add(Dense(4,input_dim=4,activation='relu'))
model.add(Dense(8,activation='relu'))
model.add(Dense(1,activation='sigmoid'))
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
model.fit(scaled_X_train,y_train,epochs=50,verbose=2)
print(model.fit(scaled_X_train,y_train,epochs=50,verbose=2))
These were the errors:
Traceback (most recent call last):
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/usr/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: librccl.so: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/cemosambora/eclipse-workspace/Deep_Learning_OpenCV/kerasBasics.py", line 5, in <module>
from keras.models import Sequential
File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/__init__.py", line 3, in <module>
from . import utils
File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/utils/__init__.py", line 6, in <module>
from . import conv_utils
File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in <module>
from .. import backend as K
File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/backend/__init__.py", line 89, in <module>
from .tensorflow_backend import *
File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/usr/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: librccl.so: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
This page has some common reasons and solutions.
This error was caused by missing rccl library.
After installing rocm, you need to install some ROCm Libraries :
sudo apt-get update && sudo apt-get install -y --allow-unauthenticated rocm-dkms rocm-dev rocm-libs rccl rocm-device-libs hsa-ext-rocr-dev hsakmt-roct-dev hsa-rocr-dev rocm-opencl rocm-opencl-dev rocm-utils rocm-profiler cxlactivitylogger miopen-hip miopengemm
Bit late to respond, but here's my two-cents for what it may be worth. It is highly recommended that we use Ubuntu 18.04 per the pre-requisites and official support offered by ROCm Considering the holistic aspects of the way many eco-system oriented support that you might bump onto in this regard vis-a-vis Python Packages, GPU Support etc., this should be the best bet for you to consider; should you be serious about your endeavour in this regard.

Error in checking sklearn version

I am onto practising ML using python and visited through this link.
I installed all of the packages mentioned in the link namely, scipy, numpy, matplotlib, pandas, sklearn and implemented the following code to check their respective versions and proper installation,
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__))
but got the following error:
Traceback (most recent call last):
File "VersionCheck.py", line 19, in <module>
import sklearn
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\__init__.py", line 134, in <module>
from .base import clone
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\base.py", line 13, in <module>
from .utils.fixes import signature
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\validation.py", line 18, in <module>
from ..utils.fixes import signature
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\fixes.py", line 144, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\sparse\linalg\__init__.py", line 114, in <module>
from .isolve import *
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
To see a version of sklearn installed:
from sklearn import __version__
print(__version__)

Numpy: ImportError: cannot import name TestCase

I installed numpy from
sudo apt-get install numpy
Then in python2.7 on importing numpy with
import numpy
I get this error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 45, in <module>
from numpy.testing import Tester
File "/usr/local/lib/python2.7/dist-packages/numpy/testing/__init__.py", line 8, in <module>
from unittest import TestCase
ImportError: cannot import name TestCase
I then removed Numpy and Scipy. Then again installed from the github repo. But I still get the same error. Please help.
Thank You.
I suspect that you have a local file called unittest.py that is getting imported instead of the standard module.

Categories