Okay, so I am currently working on a project using Jupyter Notebook and had to create colormaped representations of USA counties, thus I realised that I need to install geopandas to proceed further.
So, on the mac terminal I wrote
pip install geopandas
and it installed v 0.10.2 for me.
But now when I am doing the following:
import geopandas
in notebook, it gives me this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-90-2ba400db65f5> in <module>
23 import xlrd
24 import plotly.figure_factory as ff
---> 25 import geopandas.plotting
~/opt/anaconda3/lib/python3.8/site-packages/geopandas/__init__.py in <module>
2
3 from geopandas.geoseries import GeoSeries # noqa
----> 4 from geopandas.geodataframe import GeoDataFrame # noqa
5 from geopandas.array import points_from_xy # noqa
6
~/opt/anaconda3/lib/python3.8/site-packages/geopandas/geodataframe.py in <module>
62
63
---> 64 class GeoDataFrame(GeoPandasBase, DataFrame):
65 """
66 A GeoDataFrame object is a pandas.DataFrame that has a column
~/opt/anaconda3/lib/python3.8/site-packages/geopandas/geodataframe.py in GeoDataFrame()
1851 return self.geometry.difference(other)
1852
-> 1853 plot = CachedAccessor("plot", geopandas.plotting.GeoplotAccessor)
1854
1855 #doc(_explore)
AttributeError: partially initialized module 'geopandas' has no attribute 'plotting' (most likely due to a circular import)
The complete block of code which is getting executed is as follows:
import pandas as pd
pd.options.mode.chained_assignment = None # default='warn'
import opendatasets as od
import plotly.express as px
import plotly.graph_objs as go
from plotly.offline import iplot
import seaborn as sns
import re
from plotly.offline import init_notebook_mode
init_notebook_mode(connected=True)
from wordcloud import WordCloud
from math import pi
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
from tqdm import tqdm
import shapely
import shapefile
import xlrd
import plotly.figure_factory as ff
import geopandas
Kindly explain how can I solve this error and proceed further. I have tried all from my side for couple of hours.
What exactly is this 'most likely due to a circular import'? How to resolve it?
Related
When I try to import the beginning of this code I am faced with this error:
ImportError: DLL load failed while importing _imaging: The specified module could not be found.
My code is:
# Basic Imports
import numpy as np
import matplotlib.pyplot as plt
from glob import glob
from PIL import Image
# Imports for Building CNN
from keras.layers import Input, Lambda, Dense, Flatten
from keras.models import Model
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input
from keras.preprocessing import image
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential, load_model
from tensorflow.keras.preprocessing.image import load_img
# Ignore Warnings
import warnings
warnings.filterwarnings("ignore")
The error (from jupyter notebook) appeared as:
``
ImportError Traceback (most recent call last)
Input In [5], in <cell line: 3>()
1 # Basic Imports
2 import numpy as np
3 import matplotlib.pyplot as plt
4 from glob import glob
5 from PIL import Image
File D:\Black\miniconda3\envs\tensorflow\lib\site-packages\matplotlib_init_.py:109, in
105 from packaging.version import parse as parse_version
107 # cbook must import matplotlib only within function
108 # definitions, so it is safe to import from it here.
109 from . import _api, _version, cbook, docstring, rcsetup
110 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
111 from matplotlib.cbook import mplDeprecation # deprecated
File D:\Black\miniconda3\envs\tensorflow\lib\site-packages\matplotlib\rcsetup.py:27, in
25 from matplotlib import _api, cbook
26 from matplotlib.cbook import ls_mapper
27 from matplotlib.colors import Colormap, is_color_like
28 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
29 from matplotlib._enums import JoinStyle, CapStyle
File D:\Black\miniconda3\envs\tensorflow\lib\site-packages\matplotlib\colors.py:51, in
49 from numbers import Number
50 import re
51 from PIL import Image
52 from PIL.PngImagePlugin import PngInfo
54 import matplotlib as mpl
File D:\Black\miniconda3\envs\tensorflow\lib\site-packages\PIL\Image.py:100, in
91 MAX_IMAGE_PIXELS = int(1024 * 1024 * 1024 // 4 // 3)
94 try:
95 # If the _imaging C module is not present, Pillow will not load.
96 # Note that other modules should not refer to _imaging directly;
97 # import Image and use the Image.core variable instead.
98 # Also note that Image.core is not a publicly documented interface,
99 # and should be considered private and subject to change.
100 from . import _imaging as core
102 if version != getattr(core, "PILLOW_VERSION", None):
103 raise ImportError(
104 "The _imaging extension was built for another version of Pillow or PIL:\n"
105 f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
106 f"Pillow version: {version}"
107 )
ImportError: DLL load failed while importing _imaging: The specified module could not be found.
``
I think something is outdated? if that is the case, what can I do to solve this issue?
I learned a lot of solutions from this website, but still cannot solve the problem. My code is as follows for your review:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import missingno as msno
import altair as alt
from statsmodels.graphics.mosaicplot import mosaic
from scipy.stats import chi2_contingency
import plotly.express as px
from pandas.plotting import parallel_coordinates
from wordcloud import WordCloud
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
from scipy.spatial import distance
!pip install sklearn
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
from sklearn.impute import KNNImputer
from missingpy import MissForest
import sklearn.neighbors._base
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
import warnings
warnings.filterwarnings("ignore")
And still shows the error: ModuleNotFoundError: No module named 'sklearn.neighbors.base' I've tried to do the follows:
pip install -U imbalanced-learn ;
pip install -U scikit-learn
ans there was still of no use
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_11280/2643854484.py in <module>
26 from sklearn.impute import IterativeImputer
27 from sklearn.impute import KNNImputer
---> 28 from missingpy import MissForest
29 import sklearn.neighbors._base
30 sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
C:\ProgramData\Anaconda3\lib\site-packages\missingpy\__init__.py in <module>
----> 1 from .knnimpute import KNNImputer
2 from .missforest import MissForest
3
4 __all__ = ['KNNImputer', 'MissForest']
C:\ProgramData\Anaconda3\lib\site-packages\missingpy\knnimpute.py in <module>
11 from sklearn.utils.validation import check_is_fitted
12 from sklearn.utils.validation import FLOAT_DTYPES
---> 13 from sklearn.neighbors.base import _check_weights
14 from sklearn.neighbors.base import _get_weights
15
ModuleNotFoundError: No module named 'sklearn.neighbors.base'
Finally, I solved the problem!!
I should write this before import missingpy, not behind it.
import sklearn.neighbors._base
import sys
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
from missingpy import MissForest
done.
I'm trying to download fundamental data from Yahoo Finance like PE ratios, PB ratios, EV/EBITDA, etc. This is what I've done so far:
#import required libraries
import pandas as pd
import numpy as np
import requests
import xlsxwriter
from scipy import stats
import math
import secrets
import yfinance as yf
import matplotlib.pyplot as plt
import datetime as dt
import statsmodels.api as sm
pip install requests_html
stocks = pd.read_csv('constituents.csv')
from yahoo_fin.stock_info import get_data
sm.get_stats_valuation("aapl")
I get this error:
AttributeError Traceback (most recent call last)
<ipython-input-17-7a641ee9069d> in <module>
----> 1 sm.get_stats_valuation("aapl")
AttributeError: module 'statsmodels.api' has no attribute 'get_stats_valuation'
What do I do?
I checked the website you specified in comment. I think you can get stats valuation from stock_info module itself of the yahoo_fin package. Please check:
import yahoo_fin.stock_info as si
si.get_stats_valuation("aapl")
I'm currently having trouble importing some simple packages.
I'm working on pycharm professional in a virtual environment.
just trying to load;
import pandas as pd
import numpy as np
from sklearn.ensemble import IsolationForest
from sklearn.ensemble._iforest import _average_path_length
import shap
importError Traceback (most recent call last)
<ipython-input-1-5b7f1bf909af> in <module>
----> 1 import pandas as pd
2 import numpy as np
3 from sklearn.ensemble import IsolationForest
4 from sklearn.ensemble._iforest import _average_path_length
5 import shap
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pandas\__init__.py in <module>
14
15 if missing_dependencies:
---> 16 raise ImportError(
17 "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
18 )
ImportError: Unable to import required dependencies:
numpy: cannot import name 'asanyarray' from 'numpy.core.multiarray' (C:\Users\James\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\numpy\core\multiarray.py
I've never come across this error before so don't know how to fix.
I am trying to run a simple code and I have all the dependencies for matplotlib and numpy installed in my Canopy. Still I am getting error.
import cv2
import numpy as np
import matplotlib.pyplot as plt
x = cv2.imread('jay.jpg')
plt.imshow(x, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
Error:
%run "c:\users\jay\appdata\local\temp\tmppvibq9.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
c:\users\jay\appdata\local\temp\tmppvibq9.py in <module>()
2 import numpy as np
3 import matplotlib.cbook
----> 4 import matplotlib.pyplot as plt
5
6 x = cv2.imread('jay.jpg')
C:\Users\Jay\AppData\Local\Enthought\Canopy\System\Lib\site-packages\matplotlib\pyplot.py in <module>()
27 from cycler import cycler
28 import matplotlib
---> 29 import matplotlib.colorbar
30 from matplotlib import style
31 from matplotlib import _pylab_helpers, interactive
C:\Users\Jay\AppData\Local\Enthought\Canopy\System\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
C:\Users\Jay\AppData\Local\Enthought\Canopy\System\Lib\site-packages\matplotlib\artist.py in <module>()
9 import numpy as np
10 import matplotlib
---> 11 import matplotlib.cbook as cbook
12 from matplotlib.cbook import mplDeprecation
13 from matplotlib import docstring, rcParams
AttributeError: 'module' object has no attribute 'cbook'
Dependencies I have installed for numpy and matplotlib:
1.) libsvm-3.17.win64-py2.7
2.) pyparsing-2.0.3-1.win64-py2.7
3.) python-dateutil-2.4.2-2.win64-py2.7
4.) pytz-2015.7-1.win64-py2.7
5.) six-1.10.0-1.win64-py2.7
6.) scipy-0.13.3.win64-py2.7
7.) numpy-MKL-1.9.2-2.win64-py2.7
8.) Matplotlib 1.5.1-win64-py2.7
9.) pip 8.0.2-1.win64-py2.7
Try this:
Close your jupyter notebook and terminate ipython.
Restart Terminal
Enter this command in Terminal:
export LANG=en_US.UTF-8;export LC_ALL=en_US.UTF-8
Re-run your ipython / Jupyter notebook now. It works like a charm.
conda install matplotlib --force
I don't know for sure that this is causing your problem, but you are running your code in the wrong Python environment:
C:\Users\Jay\AppData\Local\Enthought\Canopy\System\
You should be running it in
C:\Users\Jay\AppData\Local\Enthought\Canopy\User
See
https://support.enthought.com/entries/23646538-Make-Canopy-User-Python-be-your-default-Python
and
http://docs.enthought.com/canopy/configure/faq.html#where-are-all-of-the-python-packages-in-my-user-python-environment
You can find which 'matplotlib.py' is imported and then open that file and check if it has 'cbook' or not.
import imp
imp.find_module("matplotlib")
i had the same problem and it was because of this line :
from sys import stdout
i deleted this import and the problem is gone now