ImportError: cannot import name 'get_versions' from 'matplotlib._version' - numpy

When doing my imports:
import cv2
from matplotlib import pyplot as plt
import numpy as np
import opencv_wrapper as cvw
I get:
ImportError Traceback (most recent call last)
/var/folders/bw/fb7g3vhj2ln41zrg3v5ynnn40000gn/T/ipykernel_96862/883562467.py in <module>
1 # import the necessary packages
2 import cv2
----> 3 from matplotlib import pyplot as plt
4 import numpy as np
5 import opencv_wrapper as cvw
/opt/anaconda3/envs/py37/lib/python3.7/site-packages/matplotlib/__init__.py in <module>
114 # Get the version from the _version.py versioneer file. For a git checkout,
115 # this is computed based on the number of commits since the last tag.
--> 116 from ._version import get_versions
117 __version__ = str(get_versions()['version'])
118 del get_versions
ImportError: cannot import name 'get_versions' from 'matplotlib._version' (/opt/anaconda3/envs/py37/lib/python3.7/site-packages/matplotlib/_version.py)
I'm using:
matplotlib 3.4.3
numpy 1.16.2
opencv-python 4.0.0.21
opencv-wrapper 0.2.3
python 3.7.13
Due to the opencv wrapper these are the versions I need to use.
I've tried to uninstall and reinstall but the error persists. Any help will be appreciated.

Related

ImportError: cannot import name '_backports' from 'matplotlib.cbook'

---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_22516\254480426.py in <module>
2 import matplotlib.pyplot as plt
3 from mpl_toolkits.mplot3d import Axes3D, art3d # NOQA
----> 4 from matplotlib.cbook import _backports
5 from collections import defaultdict
6 import types
ImportError: cannot import name '_backports' from 'matplotlib.cbook' (C:\Users\saidt\anaconda3\envs\tensorflow\lib\site-packages\matplotlib\cbook\__init__.py)
I cannot solve this problem. I tried several ways advised on other posts (uninstalled, reinstalled, changed the version of matplotlib) but still have this issue. I even checked matplotlib.cbook (https://matplotlib.org/stable/api/cbook_api.html) but there is no _backports. I wonder where to find the solution. If someone could help, I would really appreciate it.

How can I install GEOS?

I have problems installing basemap.
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
I get the following error:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-1-db2649dcf0a1> in <module>
2 import numpy as np
3 import matplotlib.pyplot as plt
----> 4 from mpl_toolkits.basemap import Basemap
~/opt/anaconda3/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py in <module>
154 # create dictionary that maps epsg codes to Basemap kwargs.
155 pyproj_datadir = os.environ['PROJ_LIB']
--> 156 epsgf = open(os.path.join(pyproj_datadir,'epsg'))
157 epsg_dict={}
158 for line in epsgf:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/andreamathis/opt/anaconda3/share/proj/epsg'
It looks that a the file 'epsg' is missing. Has somebody encountered this error before and knows how to solve the problem?

Why there is giving, name 'pd ' is not defined error?

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
dataset = pd.read_csv('homeprice.csv')
print(dataset)
Output
NameError Traceback (most recent call
last) in
----> 1 dataset = pd.read_csv('homeprice.csv')
2 print(dataset)
NameError: name 'pd' is not defined
You mention that you are using a Jupiter notebook so you may have two code cells:
First is with the imports:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
And the second is with the functionality:
dataset = pd.read_csv('homeprice.csv')
print(dataset)
In Jupiter notebooks you may run each cell separately. If this is what you do, you should remember the run the first cell before you execute the second one for the first time. This would make sure the right stuff is imported in the current context for you second cell.
!pip install tensorflow-gpu==2.2.0.0rc2
import tensorflow as tf
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
Or
Just go with the latest TensorFlow version in the Colab

I am not able to import statsmodel.api into kaggle kernel

I updated the statsmodels package in the kaggle kernel successfully using the code:
!pip install statsmodels --upgrade
This gave me the version of (0.10.0). However when I try to import statsmodels.api it giving me an error.
import statsmodels.api as sm
The error I am getting is:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-3b8b7e2c2e57> in <module>
8 import matplotlib.pyplot as plt
9 from sklearn.preprocessing import Normalizer
---> 10 import statsmodels.api as sm
11
12 # Input data files are available in the "../input/" directory.
/opt/conda/lib/python3.6/site-packages/statsmodels/api.py in <module>
16 from . import robust
17 from .robust.robust_linear_model import RLM
---> 18 from .discrete.discrete_model import (Poisson, Logit, Probit,
19 MNLogit, NegativeBinomial,
20 GeneralizedPoisson,
/opt/conda/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py in <module>
43
44 from statsmodels.base.l1_slsqp import fit_l1_slsqp
---> 45 from statsmodels.distributions import genpoisson_p
46
47 try:
/opt/conda/lib/python3.6/site-packages/statsmodels/distributions/__init__.py in <module>
1 from statsmodels.tools._testing import PytestTester
2 from .empirical_distribution import ECDF, monotone_fn_inverter, StepFunction
----> 3 from .edgeworth import ExpandedNormal
4 from .discrete import genpoisson_p, zipoisson, zigenpoisson, zinegbin
5
/opt/conda/lib/python3.6/site-packages/statsmodels/distributions/edgeworth.py in <module>
5 import numpy as np
6 from numpy.polynomial.hermite_e import HermiteE
----> 7 from statsmodels.compat.scipy import factorial
8 from scipy.stats import rv_continuous
9 import scipy.special as special
ImportError: cannot import name 'factorial'
I've upgraded the scipy package, and I am still getting the same error. I am new to Kaggle and Python and I need the OLS function to do regression analysis. How can I fix this problem? If not, is there any other function I can use to get a regression summary?

Getting importerror when importing matplotlib.pyplot

So Im getting the following error when I import matplotlib.pyplot:
ImportError Traceback (most recent call last)
<ipython-input-18-413b0dcce8d2> in <module>()
1 import pandas as pd
----> 2 import matplotlib.pyplot as plt
3 data=pd.read_csv("fifa_countries_audience.csv")
4 del data['country']
5 print(data)
~\Anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>()
30 from cycler import cycler
31 import matplotlib
---> 32 import matplotlib.colorbar
33 from matplotlib import style
34 from matplotlib import _pylab_helpers, interactive
~\Anaconda3\lib\site-packages\matplotlib\colorbar.py in <module>()
30
31 import matplotlib as mpl
---> 32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
34 import matplotlib.collections as collections
~\Anaconda3\lib\site-packages\matplotlib\artist.py in <module>()
14 import matplotlib
15 from . import cbook, docstring, rcParams
---> 16 from .path import Path
17 from .transforms import (Bbox, IdentityTransform, Transform, TransformedBbox,
18 TransformedPatchPath, TransformedPath)
~\Anaconda3\lib\site-packages\matplotlib\path.py in <module>()
24
25 from . import _path, rcParams
---> 26 from .cbook import (_to_unmasked_float_array, simple_linear_interpolation,
27 maxdict)
28
ImportError: cannot import name '_to_unmasked_float_array'
Anyone has idea what might be the case? I tried reinstalling matplotlib, updating it, updating conda but it didnt solve the case.