I've seen so many questions about this error online, but even after reading through all of them, I have no idea why I am still getting this error. I have spicy installed, and I am completely lost as to what to do. All I'm trying to do is get an example working that I found online, but this ModuleError keeps appearing.
Here are the imports below:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import Normalize
from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris
from sklearn.model_selection import StratifiedShuffleSplit
from sklearn.model_selection import GridSearchCV
Traceback (most recent call last):
File "/Users/.../PycharmProjects/SVM/venv/example1.py", line 11, in <module>
from sklearn.datasets import load_iris
File "/anaconda3/lib/python3.7/site-packages/sklearn/datasets/__init__.py", line 48, in <module>
from ._olivetti_faces import fetch_olivetti_faces
File "/anaconda3/lib/python3.7/site-packages/sklearn/datasets/_olivetti_faces.py", line 20, in <module>
from scipy.io.matlab import loadmat
File "/anaconda3/lib/python3.7/site-packages/scipy/io/__init__.py", line 97, in <module>
from .matlab import loadmat, savemat, whosmat, byteordercodes
ModuleNotFoundError: No module named 'scipy.io.matlab'
Any suggestions would be appreciated so much!! I am using Mac OS, and I have 3.7 python installed through Anaconda.
Try creating a fresh environment and install your packages with conda.
conda create -n testenv python=3.7 matplotlib numpy scikit-learn scipy
Then run your code within this environment.
Related
I am attempting to build an exe file that utilizes statsmodels via PyInstaller, from the terminal. The exe file is built by PyInstaller without error--however when run I get the following error:
ModuleNotFoundError: No module named 'statsmodels.__init__._version'
I have tried installing the statsmodels hook in the PyInstaller "hooks" directory, as described here, however that does not work. I have also attempted to explicitly import statsmodels.init._version in my Python code, but that has also not worked. Below is the top of my code where I import the packages:
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.neighbors import NearestNeighbors, KNeighborsClassifier
import numpy as np
import matplotlib.pylab as plt
from sklearn.linear_model import LogisticRegression
import statsmodels.api as sm
from scipy import stats
from sklearn import datasets, neighbors
from mlxtend.plotting import plot_decision_regions
import seaborn as sns
from tqdm import tqdm
import matplotlib.ticker as mtick
from tkinter import *
from tkinter.filedialog import askopenfilename
import sklearn.utils._cython_blas
import sklearn.neighbors.typedefs
import statsmodels.tsa.statespace._filters
import statsmodels.tsa.statespace._filters._conventional
import statsmodels.tsa.statespace._filters._univariate
import statsmodels.tsa.statespace._filters._univariate_diffuse
import statsmodels.tsa.statespace._filters._inversions
import statsmodels.tsa.statespace._smoothers
import statsmodels.tsa.statespace._smoothers._conventional
import statsmodels.tsa.statespace._smoothers._univariate
import statsmodels.tsa.statespace._smoothers._univariate_diffuse
import statsmodels.tsa.statespace._smoothers._classical
import statsmodels.tsa.statespace._smoothers._alternative
import statsmodels.__init__._version
Here is the traceback of the error:
File "LR.py", line 9, in <module>
File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "statsmodels/api.py", line 32, in <module>
File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "statsmodels/__init__.py", line 2, in <module>
ModuleNotFoundError: No module named 'statsmodels.__init__._version'
What can I do to fix this so that the exe file includes the statsmodels package and can be run?
statsmodels version is accessed through the __version__ attribute.
import statsmodels
print(statsmodels.__version__)
which shows
v0.12.0rc0+20.g98dfc0073
on my system.
You should replace import statsmodels.__init__._version with from statsmodels.__init__ import __version__
This question already has answers here:
Unable to import pandas (pandas._libs.window.aggregations)
(2 answers)
Closed 2 years ago.
Trying just the following code in beginning to make sure that necessary API is installed and accessible.
from pandas import read_csv
from pandas.plotting import scatter_matrix
from matplotlib import pyplot
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import StratifiedKFold
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis importLinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
print("Testing of installation successful..Go Ahead.")
However, getting the following error:
Traceback (most recent call last):
File "C:\Python\test_ml.py", line 3, in <module>
from pandas import read_csv
File "C:\Python\lib\site-packages\pandas\__init__.py", line 55, in <module>
from pandas.core.api import (
File "C:\Python\lib\site-packages\pandas\core\api.py", line 29, in <module>
from pandas.core.groupby import Grouper, NamedAgg
File "C:\Python\lib\site-packages\pandas\core\groupby\__init__.py", line 1, in <module>
from pandas.core.groupby.generic import DataFrameGroupBy, NamedAgg, SeriesGroupBy
File "C:\Python\lib\site-packages\pandas\core\groupby\generic.py", line 60, in <module>
from pandas.core.frame import DataFrame
File "C:\Python\lib\site-packages\pandas\core\frame.py", line 124, in <module>
from pandas.core.series import Series
File "C:\Python\lib\site-packages\pandas\core\series.py", line 4572, in <module>
Series._add_series_or_dataframe_operations()
File "C:\Python\lib\site-packages\pandas\core\generic.py", line 10349, in _add_series_or_dataframe_operations
from pandas.core.window import EWM, Expanding, Rolling, Window
File "C:\Python\lib\site-packages\pandas\core\window\__init__.py", line 1, in <module>
from pandas.core.window.ewm import EWM # noqa:F401
File "C:\Python\lib\site-packages\pandas\core\window\ewm.py", line 5, in <module>
import pandas._libs.window.aggregations as window_aggregations
ImportError: DLL load failed while importing aggregations: The specified module could not be found.
Kindly provide me the solution.I am using Python 3.8.2 and IDLE 3.8.32
Seems it is an issue with the latest version of pandas.
Try installing an older version:
pip uninstall pandas
pip install pandas==1.0.1
Original answer:
Unable to import pandas (pandas._libs.window.aggregations)
I am getting the error "ImportError: No module named Tkinter" but don't know why.
When I run my script I am getting this error but that is usually do to a library you are trying to use that you have not imported. I have searched and all of the posts I have found are directly related to someone ether messing up "Tkinter" with "tkinter" python 2 and 3, or have not imported the library the right way. I have ran this script from the command line on ubuntu 14.04, Spyder on the same Ubuntu box, and also on the Cloudera Data Science workbench and it worked fine. On all of these machines I have not imported the library and it works flawlessly.
When I try to run it on my rhel 7 box I am getting the following error:
root#rhel7_box:/home/user/4688_events_PC-Tags_last_7_days# python 4688_events_PC-Tags_last_7_days_NN_FromMergedHash.py
Traceback (most recent call last):
File "4688_events_PC-Tags_last_7_days_NN_FromMergedHash.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
from . import tkagg # Paint image to Tk photo blitter extension.
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
from six.moves import tkinter as Tk
File "/usr/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
ImportError: No module named Tkinter
It seems to be getting the error when it hits "import matplotlib.pyplot as plt".
These are the libraries that I am using that work fine everywhere else:
#Libraries
import pandas as pd
import numpy as np
import hashlib
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
import keras
from keras.models import Sequential
from keras.layers import Dense
from sklearn.metrics import confusion_matrix
tkinter is used as a UI processing backend for matplotlib. It should be shipped with python but might not be on your system for various reasons. Chances are you you have agg, (should ship with ubuntu) which you can use instead.
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
You can of course still use tkinter if you install it on your box. If you prefer that for some reason I can let you know but it requires sudo.
I am using Python 2.7.10 and have installed scikit-0.15.2 using pip and i already have "numpy-1.1.10" and "scipy-0.16.0" installed and it works fine but when i try to import TfidfVectorizer from sklearn to construct a term document matrix with tf-idf values
from sklearn.feature_extraction.text import TfidfVectorizer
i get an error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import sklearn
File "C:\Python27\lib\site-packages\sklearn\__init__.py", line 37, in <module>
from . import __check_build
ImportError: cannot import name __check_build
I have already gone through the earlier post and tried the solutions but it didn't work.
For windows user try to install numpy+mkl package from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn
and after successful installation restart the python
Had the same problem. installing scipy solved the problem for me.
Try...
#sudo pip install scipy
What does it say if you fire up a python prompt and type
import scipy
also there might be some pointers in this thread ImportError in importing from sklearn: cannot import name check_build
I am trying to run a python script which has the following statements:
import random as RD
import pylab as PL
import scipy as SP
import networkx as NX
Where can I download these packages?
I have installed these packages and I get the following error when I run my code
I am getting the following error when I run the code
Traceback (most recent call last):
File "C:\Documents and Settings\hplabs\Desktop\Dushyant\networkdemo.py", line 7, in <module>
import pylab as PL
File "C:\Python26\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python26\lib\site-packages\matplotlib\__init__.py", line 129, in <module>
from rcsetup import defaultParams, validate_backend, validate_toolbar
File "C:\Python26\lib\site-packages\matplotlib\rcsetup.py", line 19, in <module>
from matplotlib.colors import is_color_like
File "C:\Python26\lib\site-packages\matplotlib\colors.py", line 52, in <module>
import numpy as np
ImportError: No module named numpy
Here's a link to the non standard libraries. random is part of the standard library.
matplotlib
scipy
networkX
numpy (reuired by scipy)
'random' is shipped with the standard library
pylab and scipy are part of SciPy
Networkx is available here
random is a standard python library module, no need to install that.
pylab and scipy can be found on the SciPy site
networkx also has a site
BTW: These are all easily found using google.com
When installing Scipy, you also need to install numpy which it depends on. See here. You are getting the error because numpy is not installed on your system.