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)
Related
Trying to run some machine learning examples so am importing some packages
sklearn version 0.22.1
tensorflow version 2.3.0
keras version 2.3.0
in the following way:
import os
import sys
import math
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 matplotlip.pyplot as plt
I am getting the import error:
ImportError: cannot import name 'Sequence'
Full traceback:
File "C:\Anaconda\lib\site-packages\keras\__init__.py", line 12, in <module>
from . import callbacks
File "C:\Anaconda\lib\site-packages\keras\callbacks\__init__.py", line 3, in <module>
from .callbacks import Callback
File "C:\Anaconda\lib\site-packages\keras\callbacks\callbacks.py", line 23, in <module>
from ..engine.training_utils import standardize_input_data
File "C:\Anaconda\lib\site-packages\keras\engine\training_utils.py", line 18, in <module>
from ..utils import Sequence
ImportError: cannot import name 'Sequence'
I have looked on line for help trying a few different tensorflow and keras versions. I have also tried:
import tensorflow.keras as keras
and import tensorflow.keras.utils import Sequence
without success
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__
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.
This question already has answers here:
ImportError: cannot import name cross_validation
(4 answers)
Closed 4 years ago.
Here is my code Please Help. I'm a beginner.
import pandas as pd
import sklearn
from sklearn.feature_selection import SelectFromModel
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
from sklearn import cross_validation
I'm using the latest version of Sklearn but I'm getting this error
On Windows:
Traceback (most recent call last): File "MalwareDetector.py", line
8, in
from sklearn import cross_val_score ImportError: cannot import name 'cross_val_score' from 'sklearn'
(C:\Users\richa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sklearn__init__.py)
On Ubuntu:
Traceback (most recent call last): File "MalwareDetector.py", line 8,
in from sklearn import cross_validation ImportError: cannot
import name cross_validation
cross_validation is deprecated since version 0.18. This module will be removed in 0.20.
Use sklearn.model_selection.train_test_split instead.
from sklearn.model_selection import train_test_split
More:
sklearn 0.19 docs
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.