IPython fails to import Geopandas - python

After successfully installing the Geopandas conda package from the conda-forge as follows:
conda install -c conda-forge geopandas
When I try to import it in IPython (Jupyter notebook), using:
import geopandas as gpd
I consistently receive the following error, despite having all the dependencies (numpy, pandas, shapely, fiona, six, pyproj) installed and up-to-date:
---------------------------------------------------------------------
------
ImportError Traceback (most recent call
last)
<ipython-input-1-13760ce748ee> in <module>()
4 import matplotlib.mlab as mlab
5
----> 6 import geopandas as gpd
7 import seaborn as sns
8 from sklearn import preprocessing
//anaconda/lib/python2.7/site-packages/geopandas/__init__.py in <module>()
----> 1 from geopandas.geoseries import GeoSeries
2 from geopandas.geodataframe import GeoDataFrame
3
4 from geopandas.io.file import read_file
5 from geopandas.io.sql import read_postgis
//anaconda/lib/python2.7/site-packages/geopandas/geoseries.py in <module>()
6 from pandas import Series, DataFrame
7 from pandas.core.indexing import _NDFrameIndexer
----> 8 from pandas.util.decorators import cache_readonly
9 import pyproj
10 from shapely.geometry import box, shape, Polygon, Point
ImportError: No module named decorators
Any suggestions on what might be causing the error?

To make the comment of Jeff stand out more, this was fixed in pandas 0.20.1.
So normally, if you now install the latest pandas version (not 0.20.0), you should not get this error.

Related

issue importing module in python jupyter

hi so I'm trying to import geopandas into my script
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
#handling txt
#remove 'lat=' and 'long=' then type change from object to float to make point.
df = pd.read_csv('latlong.txt', header=None, names = ['lat','long', 'name','description'])
df['lat'] = df['lat'].str.replace('lat=', '')
df['long'] = df['long'].str.replace('long=', '')
df['lat'] = df['lat'].astype(float)
df['long'] = df['long'].astype(float)
#make point geometry
df['geometry'] = df.apply(lambda row: Point(low['long'], low['lat']), axis=1) #long is X, lat is Y
#change df to gdf
gdf = gpd.GeoDataFrame(df, geometry = 'geometry', crs='EPSG:4326') #epsg4326 is WGS84
But when I try to run this in the jupyter notebook, using a conda environment from these steps: https://medium.com/#nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook-in-just-4-steps-abeab8b8d084
I get the following error :
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_2312/3230284861.py in <module>
----> 1 import pandas as pd
2 import geopandas as gpd
3 from shapely.geometry import Point
4
5 #handling txt
~\.conda\envs\geojsongen\lib\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:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "C:\Users\User\.conda\envs\geojsongen\python.exe"
* The NumPy version is: "1.21.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
I installed the geopandas in this environment using the following command:
conda install -c conda-forge geopandas
Could someone advise me on how I can fix these errors? Any help is appreciated, thank you!!
edit:
I tried this pip install --upgrade --force-reinstall numpy, thanks #krmogi for this, but now I get this error, it looks like an issue with my geopandas installation? :
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13932/3230284861.py in <module>
1 import pandas as pd
----> 2 import geopandas as gpd
3 from shapely.geometry import Point
4
5 #handling txt
~\.conda\envs\geojsongen\lib\site-packages\geopandas\__init__.py in <module>
----> 1 from geopandas._config import options # noqa
2
3 from geopandas.geoseries import GeoSeries # noqa
4 from geopandas.geodataframe import GeoDataFrame # noqa
5 from geopandas.array import points_from_xy # noqa
~\.conda\envs\geojsongen\lib\site-packages\geopandas\_config.py in <module>
107 use_pygeos = Option(
108 key="use_pygeos",
--> 109 default_value=_default_use_pygeos(),
110 doc=(
111 "Whether to use PyGEOS to speed up spatial operations. The default is True "
~\.conda\envs\geojsongen\lib\site-packages\geopandas\_config.py in _default_use_pygeos()
93
94 def _default_use_pygeos():
---> 95 import geopandas._compat as compat
96
97 return compat.USE_PYGEOS
~\.conda\envs\geojsongen\lib\site-packages\geopandas\_compat.py in <module>
7 import numpy as np
8 import pandas as pd
----> 9 import pyproj
10 import shapely
11 import shapely.geos
~\.conda\envs\geojsongen\lib\site-packages\pyproj\__init__.py in <module>
47 import warnings
48
---> 49 import pyproj.network
50 from pyproj._datadir import ( # noqa: F401 pylint: disable=unused-import
51 _pyproj_global_context_initialize,
~\.conda\envs\geojsongen\lib\site-packages\pyproj\network.py in <module>
8 import certifi
9
---> 10 from pyproj._network import ( # noqa: F401 pylint: disable=unused-import
11 _set_ca_bundle_path,
12 is_network_enabled,
ImportError: DLL load failed while importing _network: The specified module could not be found.
Your issue is happening here as shown in your traceback
----> 1 import pandas as pd
Make sure you have pandas installed.
pip install pandas
It also says that numpy C-extentions failed. Install numpy as well:
pip install numpy
While you're at it, make sure you have the other modules installed as well.
If you're still getting the same error, it's possible that setuptools is not properly installed. Do this:
pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy
If you still don't have any luck, try this:
pip install --upgrade --force-reinstall numpy

I am facing this issue in seaborn import:

When I try running following line in Jupiter notebook
> import seaborn as sns
I get this error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-ed9806ce3570> in <module>()
----> 1 import seaborn as sns
~/anaconda3/lib/python3.6/site-packages/seaborn/__init__.py in <module>()
8 from .palettes import *
9 from .regression import *
---> 10 from .categorical import *
11 from .distributions import *
12 from .timeseries import *
~/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in <module>()
5 from scipy import stats
6 import pandas as pd
----> 7 from pandas.core.series import remove_na
8 import matplotlib as mpl
9 from matplotlib.collections import PatchCollection
ImportError: cannot import name 'remove_na'
dependency versions are listed below:
Python 3.6.3
conda 4.8.2
numpy 1.18.0
pandas 1.0.1
scipy 1.1.0
matplotlib 3.1.3
What is the issue here?
Okay,
so I still dont know, what was wrong in this, but I did solve the problem.
I simply uninstalled seaborn
pip3 uninstall seaborn
and installed it again
pip3 install seaborn
it worked, no error this time.
But I still dont know, what went wrong first time.
If someone can help please share.
The problem is that seaborn seems to be using a private method from pandas. The issue has been reported to both pandas and seaborn developers (see https://github.com/pandas-dev/pandas/issues/16971 and https://github.com/mwaskom/seaborn/pull/1241) which both published a fix in later versions.
The fixed version is available on pip but not on Ubuntu's packages yet (as of August 2020).
However, for those who don't want pip install, the fix is straightforward and can be manually applied (see the pull request above).

How to use packages that still use deprecated package scipy.wave?

Some old packages need deprecated scipy.weave package, like pydelay.
Installing weave from pip does not work for them.
What is the solution?
Edit:
In [1]: import pydelay
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-b743be9b35c7> in <module>()
----> 1 import pydelay
/usr/local/lib/python2.7/dist-packages/pydelay/__init__.py in <module>()
7 Last update: 23.10.2009
8 """
----> 9 from _dde23 import dde23
10 #from constantStepper import dde3
11 __all__ = ['dde23', 'gen_disconts']
/usr/local/lib/python2.7/dist-packages/pydelay/_dde23.py in <module>()
30
31 import numpy as np
---> 32 from scipy import weave
33 from scipy.interpolate import splrep, splev, spalde
34 import math
ImportError: cannot import name weave
Here is mentioned that :
Weave is the stand-alone version of the deprecated Scipy submodule scipy.weave.
Solution:
I removed the package, replaced the scipy.weave by weave in files and reinstalled by setup.py file. that's all.

No module named 'folium.plugins', Python 3.6

I am trying to import folium into a Jupyter notebook I'm working on and I cannot seem to solve the import issues with the Folium library. Has anyone else solved this problem?
After encountering an error installing folium, I used the solution provided in this thread to install the module:
Python 3.6 Module cannot be found: Folium
Short summary: clone from github, install using the commandline.
This worked, but instead I encountered the following error further down the line when trying to import folium into my notebook:
Input:
import pandas as pd
import geopandas as gpd
import numpy as np
from geopandas.tools import sjoin
import folium
from folium.plugins import MarkerCluster
from folium.element import IFrame
import shapely
from shapely.geometry import Point
import unicodedata
import pysal as ps
Output:
ModuleNotFoundError Traceback (most recent call
last)
<ipython-input-162-0ae99a5c599e> in <module>()
4 from geopandas.tools import sjoin
5 import folium
----> 6 from folium.plugins import MarkerCluster
7 from folium.element import IFrame
8 import shapely
ModuleNotFoundError: No module named 'folium.plugins'
I have no idea why this works, but I was having the same problem and finally solved it with
import folium.plugins as plugins
cluster = folium.FeatureGroup(name='cluster')
cluster.add_child(plugins.MarkerCluster(locations=coords, popups=popups)

Mac geopandas import error

I am having some trouble trying to import geopandas in my Mac. I installed it by the conda command:
conda install -c conda-forge geopandas
After I try to import by I get the following error:
ImportError Traceback (most recent call last)
<ipython-input-2-e508418be6dd> in <module>()
1 import pandas as pd
----> 2 import geopandas as gpd
3 get_ipython().magic('matplotlib inline')
/anaconda/lib/python3.6/site-packages/geopandas/__init__.py in <module>()
2 from geopandas.geodataframe import GeoDataFrame
3
----> 4 from geopandas.io.file import read_file
5 from geopandas.io.sql import read_postgis
6 from geopandas.tools import sjoin
/anaconda/lib/python3.6/site-packages/geopandas/io/file.py in <module>()
1 import os
2
----> 3 import fiona
4 import numpy as np
5
/anaconda/lib/python3.6/site-packages/fiona/__init__.py in <module>()
67 from six import string_types
68
---> 69 from fiona.collection import Collection, BytesCollection, vsi_path
70 from fiona._drivers import driver_count, GDALEnv
71 from fiona.drvsupport import supported_drivers
/anaconda/lib/python3.6/site-packages/fiona/collection.py in <module>()
7
8 from fiona import compat
----> 9 from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
10 from fiona.ogrext import Session, WritingSession
11 from fiona.ogrext import (
ImportError: dlopen(/anaconda/lib/python3.6/site-packages/fiona/ogrext.cpython-36m-darwin.so, 2): Library not loaded: #rpath/libxerces-c-3.1.dylib
Referenced from: /anaconda/lib/libgdal.20.dylib
Reason: image not found
I tried updating my anaconda by running:
conda update conda
Got the same error, so I tried uninstalling with conda and installing with pip. Got the same error.
Then I tried to forge fiona with conda,then installing with pip but it got me nowhere, and now I'm stuck. Any ideas?
I think could have been a problem with the conda-forge feedstock for fiona:
https://github.com/conda-forge/fiona-feedstock/issues/62
I had the same problem a few days ago but it seems to have been resolved now. Have you tried again?

Categories

Resources