python cannot import name 'is_list_like' [duplicate] - python

This question already has answers here:
import pandas_datareader gives ImportError: cannot import name 'is_list_like'
(6 answers)
Closed 4 years ago.
I am trying to run the following code using pandas_datareader on PYTHON 3.6.5 IDLE(WIN 10 SYS).
#import our Python libraries
import os
import sys
import pandas as pd
import pandas_datareader.data as web
import numpy as np
import statsmodels.formula.api as smf
import statsmodels.tsa.api as smt #tsa为Time Series analysis缩写
import statsmodels.api as sm
import scipy.stats as scs
from arch import arch_model
import matplotlib.pyplot as plt
import matplotlib as mpl
%matplotlib inline
It seems work on IDE eclipse, but when I try to run it on jupyter notebook, although i have installed the pandas_datareader package, jupyter continues
to stop with the following errors. I have checked that it is not concerned with any circular references or any file name conflicts.Why does it happen?
ImportError Traceback (most recent call last)
<ipython-input-4-4b149e7cab54> in <module>()
4
5 import pandas as pd
----> 6 import pandas_datareader.data as web
7 import numpy as np
8
d:\programs\python\python36\lib\site-packages\pandas_datareader\__init__.py in <module>()
1 from ._version import get_versions
----> 2 from .data import (DataReader, Options, get_components_yahoo,
3 get_dailysummary_iex, get_data_enigma, get_data_famafrench,
4 get_data_fred, get_data_google, get_data_moex,
5 get_data_morningstar, get_data_quandl, get_data_stooq,
d:\programs\python\python36\lib\site-packages\pandas_datareader\data.py in <module>()
12 ImmediateDeprecationError
13 from pandas_datareader.famafrench import FamaFrenchReader
---> 14 from pandas_datareader.fred import FredReader
15 from pandas_datareader.google.daily import GoogleDailyReader
16 from pandas_datareader.google.options import Options as GoogleOptions
d:\programs\python\python36\lib\site-packages\pandas_datareader\fred.py in <module>()
----> 1 from pandas.core.common import is_list_like
2 from pandas import concat, read_csv
3
4 from pandas_datareader.base import _BaseReader
5
ImportError: cannot import name 'is_list_like'

This is a known issue of pandas-datareader and will be fixed on release 0.7.0 as stated here.
For now, you could try to use the development version based on its master branch.

Related

ModuleNotFoundError: No module named 'matplotlib.colors',

When I try to launch jupyter notebook, I get this from anaconda prompt
enter image description here
after launching jupyter notebook, I get this on anaconda prompt before jupyter notebook opens in browser
enter image description here
after running the following import code:
import pandas as pd
import numpy as np
import seaborn as sn
from sklearn import datasets
from sklearn import metrics
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
from sklearn.tree import export_graphviz
i get the following error:
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_6884\4230379327.py in <module>
4 import pandas as pd
5 import numpy as np
----> 6 import seaborn as sn
7 from sklearn import datasets
8 from sklearn import metrics
~\Anaconda3\lib\site-packages\seaborn\__init__.py in <module>
1 # Import seaborn objects
----> 2 from .rcmod import * # noqa: F401,F403
3 from .utils import * # noqa: F401,F403
4 from .palettes import * # noqa: F401,F403
5 from .relational import * # noqa: F401,F403
~\Anaconda3\lib\site-packages\seaborn\rcmod.py in <module>
5 import matplotlib as mpl
6 from cycler import cycler
----> 7 from . import palettes
8
9
~\Anaconda3\lib\site-packages\seaborn\palettes.py in <module>
7 from .external import husl
8
----> 9 from .utils import desaturate, get_color_cycle
10 from .colors import xkcd_rgb, crayons
11
~\Anaconda3\lib\site-packages\seaborn\utils.py in <module>
11 import pandas as pd
12 import matplotlib as mpl
---> 13 import matplotlib.colors as mplcol
14 import matplotlib.pyplot as plt
15 from matplotlib.cbook import normalize_kwargs
ModuleNotFoundError: No module named 'matplotlib.colors'
when i comment the line giving the above error #import seaborn as sn i get the following error:
ImportError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_6884\1207372402.py in <module>
8 from sklearn import metrics
9 from sklearn import tree
---> 10 from sklearn.tree import DecisionTreeClassifier
11 from sklearn.tree import DecisionTreeRegressor
12 from sklearn.model_selection import train_test_split
ImportError: cannot import name 'DecisionTreeClassifier' from 'sklearn.tree' (unknown location)
when I run pip list, it shows that I have both seaborn 0.11.2 and scikitlearn 1.0.2 installed.
what could be wrong and how do i fix this?

Problem with 'cdqa': cannot import name 'TemporaryResourcesManager' from 'joblib._memmapping_reducer'

I am trying to use the cdqa library (https://github.com/cdqa-suite/cdQA). I cloned the GitHub repository using "git clone" and changed the specified versions of pandas and pytorch in the "requirements.txt" file for my versions (because I had problems installing the specific versions requested for these two libraries and, according to the "issues" in that github repository, several people managed to install cdqa by changing the versions in "requirements.txt"). Then, I used:
cd cdQA
pip install -e .
Now, I'm running the example that is in that library's GitHub repository:
import pandas as pd
from ast import literal_eval
from cdqa.utils.filters import filter_paragraphs
from cdqa.utils.download import download_model, download_bnpp_data
from cdqa.pipeline.cdqa_sklearn import QAPipeline
#from cdqa.pipeline import QAPipeline
# Download data and models
download_bnpp_data(dir='./data')
download_model(model='bert-squad_1.1', dir='./Models')
# Loading data and filtering / preprocessing the documents
df = pd.read_csv('data/bnpp_newsroom-v1.1.csv', converters={'paragraphs': literal_eval})
df = filter_paragraphs(df)
# Loading QAPipeline with CPU version of BERT Reader pretrained on SQuAD 1.1
cdqa_pipeline = QAPipeline(reader='Models/bert_qa.joblib')
but it returns the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-29-596fa5ffc73b> in <module>
4 from cdqa.utils.filters import filter_paragraphs
5 from cdqa.utils.download import download_model, download_bnpp_data
----> 6 from cdqa.pipeline.cdqa_sklearn import QAPipeline
7 #from cdqa.pipeline import QAPipeline
8
~/Documents/GIT/QA/cdQA/cdqa/pipeline/__init__.py in <module>
----> 1 from .cdqa_sklearn import QAPipeline
2
3 __all__ = ["QAPipeline"]
~/Documentos/Morning_Star_Consulting/GIT/QA/cdQA/cdqa/pipeline/cdqa_sklearn.py in <module>
----> 1 import joblib
2 import warnings
3
4 import pandas as pd
5 import numpy as np
~/anaconda3/lib/python3.8/site-packages/joblib/__init__.py in <module>
118 from .numpy_pickle import load
119 from .compressor import register_compressor
--> 120 from .parallel import Parallel
121 from .parallel import delayed
122 from .parallel import cpu_count
~/anaconda3/lib/python3.8/site-packages/joblib/parallel.py in <module>
24 from .logger import Logger, short_format_time
25 from .disk import memstr_to_bytes
---> 26 from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
27 ThreadingBackend, SequentialBackend,
28 LokyBackend)
~/anaconda3/lib/python3.8/site-packages/joblib/_parallel_backends.py in <module>
17 from .pool import MemmappingPool
18 from multiprocessing.pool import ThreadPool
---> 19 from .executor import get_memmapping_executor
20
21 # Compat between concurrent.futures and multiprocessing TimeoutError
~/anaconda3/lib/python3.8/site-packages/joblib/executor.py in <module>
10
11 from ._memmapping_reducer import get_memmapping_reducers
---> 12 from ._memmapping_reducer import TemporaryResourcesManager
13 from .externals.loky.reusable_executor import _ReusablePoolExecutor
14
ImportError: cannot import name 'TemporaryResourcesManager' from 'joblib._memmapping_reducer' (/home/user/anaconda3/lib/python3.8/site-packages/joblib/_memmapping_reducer.py)
How could I fix that error, which I think is related to joblib? Thanks a lot.
make sure your python version is >=3.8.0
modify this file
python3.8/site-packages/joblib/externals/cloudpickle/cloudpickle.py
line 135
change to
co.co_kwonlyargcount,
0,
co.co_nlocals,

cannot import name 'unicode' from 'statsmodels.compat' (c:\python\python37\lib\site-packages\statsmodels\compat\__init__.py)

I tried to import statsmodels in python, using
import statsmodels.api as sm
but I failed.
I got an error
cannot import name 'unicode' from 'statsmodels.compat'
I reinstalled and upgraded statsmodels package, but the error remains.
Could you help me to fix this error?
This is my traceback.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-125-085740203b77> in <module>
----> 1 import statsmodels.api as sm
c:\python\python37\lib\site-packages\statsmodels\api.py in <module>
7 from . import regression
8 from .regression.linear_model import OLS, GLS, WLS, GLSAR
----> 9 from .regression.recursive_ls import RecursiveLS
10 from .regression.quantile_regression import QuantReg
11 from .regression.mixed_linear_model import MixedLM
c:\python\python37\lib\site-packages\statsmodels\regression\recursive_ls.py in <module>
10 import pandas as pd
11
---> 12 from statsmodels.compat import unicode
13 from statsmodels.tools.data import _is_using_pandas
14 from statsmodels.tsa.statespace.mlemodel import (
ImportError: cannot import name 'unicode' from 'statsmodels.compat' (c:\python\python37\lib\site-packages\statsmodels\compat\__init__.py)

Can't Import ColumnTransfomer (Scikit-Learn) - Import Error:Cannot import name 'Parallel'

I use the ColumnTransfomer from Scikit-Learn and it usually works fine. Some days its decides to give me this error?
I have updated scikitlearn and it is on version 0.20. I am using Azure Notebooks (Jupyter Notebooks).
Here is the error that printed when I run:
from sklearn.compose import ColumnTransformer
ImportError Traceback (most recent call last)
<ipython-input-71-95a87d70dcfe> in <module>()
----> 1 from sklearn.compose import ColumnTransformer
~/anaconda3_501/lib/python3.6/site-packages/sklearn/compose/__init__.py in <module>()
6 """
7
----> 8 from ._column_transformer import ColumnTransformer, make_column_transformer
9 from ._target import TransformedTargetRegressor
10
~/anaconda3_501/lib/python3.6/site-packages/sklearn/compose/_column_transformer.py in <module>()
15
16 from ..base import clone, TransformerMixin
---> 17 from ..utils import Parallel, delayed
18 from ..externals import six
19 from ..pipeline import _fit_transform_one, _transform_one, _name_estimators
ImportError: cannot import name 'Parallel'
Thanks!
Vrage
You can import ColumnTransfomer when you are importing numpy in the start of the code. By importing with compose package, it will get solved. I did the same and it worked. Make sure you have installed all the packages properly.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder

Google Dopamine

I was importing some dopamine dependencies, and I got an error saying No module named DopamineKit found. I then installed it separately using the code: !pip install dopaminekit. It installed dopaminekit module, but I am still getting a similar error. I have attached my code, and error below. I would really appreciate, if anyone is able to help me through this.
import numpy as np
import os
from dopamine.agents.dqn import dqn_agent
from dopamine.atari import run_experiment
from dopamine.colab import utils as utils_colab
from absl import flags
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-18-c5b224b9c6df> in <module>()
1 import numpy as np
2 import os
----> 3 from dopamine.agents.dqn import dqn_agent
4 from dopamine.atari import run_experiment
5 from dopamine.colab import utils as utils_colab
/usr/local/lib/python3.6/dist-packages/dopamine/__init__.py in <module>()
3 ## This is solely used to import the class DopamineKit
4
----> 5 from dopaminekit import DopamineKit
/usr/local/lib/python3.6/dist-packages/dopaminekit/__init__.py in <module>()
3 ## This is solely used to import the class DopamineKit
4
----> 5 from dopaminekit import DopamineKit
ImportError: cannot import name 'DopamineKit'

Categories

Resources