Mac geopandas import error - python

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?

Related

Not able to import shapely.geometry

I am trying to import shapely but getting error.
--------------------------------------------------------------------------- OSError Traceback (most recent call last) <ipython-input-9-62e74f53568a> in <module>
----> 1 import shapely.geometry
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shapely/geometry/__init__.py in <module>
2 """
3
----> 4 from .base import CAP_STYLE, JOIN_STYLE
5 from .geo import box, shape, asShape, mapping
6 from .point import Point, asPoint
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shapely/geometry/base.py in <module>
16
17 from shapely.affinity import affine_transform
---> 18 from shapely.coords import CoordinateSequence
19 from shapely.errors import WKBReadingError, WKTReadingError
20 from shapely.geos import WKBWriter, WKTWriter
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shapely/coords.py in <module>
6 from ctypes import byref, c_double, c_uint
7
----> 8 from shapely.geos import lgeos
9 from shapely.topology import Validating
10
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shapely/geos.py in <module>
136 _lgeos = load_dll('geos_c', fallbacks=alt_paths)
137
--> 138 free = load_dll('c').free
139 free.argtypes = [c_void_p]
140 free.restype = None
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shapely/geos.py in load_dll(libname, fallbacks, mode)
60 raise OSError(
61 "Could not find lib {} or load any of its variants {}.".format(
---> 62 libname, fallbacks or []))
63
64 _lgeos = None
OSError: Could not find lib c or load any of its variants [].
I tried conda install -c conda-forge geos=3.7.1 but its not helping.
Can someone please help how can i repair Shapely. Shapely version I m using is 1.8.2.
I also tried conda install -c conda-forge geos=3.7.1 but it did not work.
I guess you are using an anaconda environment. So after you activate your environment in terminal;
conda activate <your_environment_name>
Using
pip install Shapely
in terminal, while my environment is active, I was able to use the package. Version is the 1.8.2, just like you wanted it.
For the possibility that you'd like to have a reminder on conda environments, here is a wonderful link.

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

Cannot import name 'Imputer' from 'sklearn.preprocessing' from pandas_ml

I am working on a project for my master and I was trying to get some stats on my calculations. I found a very cool tool to do this, called panda_ml, but when I import it in my cell on jupyter like this:
from pandas_ml import *
It gives me this output error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-118-93009f7254d4> in <module>
3 from sklearn import *
4 from matplotlib.colors import LogNorm
----> 5 from pandas_ml import *
6 import math
7
~/anaconda3/envs/Lab1_B/lib/python3.7/site-packages/pandas_ml/__init__.py in <module>
1 #!/usr/bin/env python
2
----> 3 from pandas_ml.core import ModelFrame, ModelSeries # noqa
4 from pandas_ml.tools import info # noqa
5 from pandas_ml.version import version as __version__ # noqa
~/anaconda3/envs/Lab1_B/lib/python3.7/site-packages/pandas_ml/core/__init__.py in <module>
1 #!/usr/bin/env python
2
----> 3 from pandas_ml.core.frame import ModelFrame # noqa
4 from pandas_ml.core.series import ModelSeries # noqa
~/anaconda3/envs/Lab1_B/lib/python3.7/site-packages/pandas_ml/core/frame.py in <module>
8
9 import pandas_ml.imbaccessors as imbaccessors
---> 10 import pandas_ml.skaccessors as skaccessors
11 import pandas_ml.smaccessors as smaccessors
12 import pandas_ml.snsaccessors as snsaccessors
~/anaconda3/envs/Lab1_B/lib/python3.7/site-packages/pandas_ml/skaccessors/__init__.py in <module>
17 from pandas_ml.skaccessors.neighbors import NeighborsMethods # noqa
18 from pandas_ml.skaccessors.pipeline import PipelineMethods # noqa
---> 19 from pandas_ml.skaccessors.preprocessing import PreprocessingMethods # noqa
20 from pandas_ml.skaccessors.svm import SVMMethods # noqa
~/anaconda3/envs/Lab1_B/lib/python3.7/site-packages/pandas_ml/skaccessors/preprocessing.py in <module>
11 _keep_col_classes = [pp.Binarizer,
12 pp.FunctionTransformer,
---> 13 pp.Imputer,
14 pp.KernelCenterer,
15 pp.LabelEncoder,
AttributeError: module 'sklearn.preprocessing' has no attribute 'Imputer'
I am using Conda, I have my own env with all the packages, I have tried to install older versions of sklearn and pandas_ml but it did not solve the problem. I've searching around but it seems that no one had ever this problem...Do you have any suggestion?
You have to uninstall properly and downgrading will work.
pip uninstall -y scikit-learn
pip uninstall -y pandas
pip uninstall -y pandas_ml
pip install scikit-learn==0.21.1
pip install pandas==0.24.2
pip install pandas_ml
Then import
from pandas_ml import *
Tested in Python 3.8.2
I had scikit-learn version 0.22.1 installed recently and had a similar problem. Then I tried your solution under Python 3.7.2, maintained the versions for Pandas v0.25.1 and Pandas ML v0.6.1 and it work like a charm!. I wonder when would be it safe to turn to a newer version of scikit-learn
from sklearn.impute import SimpleImputer
imp = SimpleImputer(missing_values=np.nan, copy=False, strategy="mean", )
No axis value is needed anymore

Issues while importing imblearn

I am trying to import SMOTE in my jupyter notebook.I tried the following steps;
I first installed imblearn using the following command in my terminal
conda install -c glemaitre imbalanced-learn
Then i used the following command to import imblearn in my notebook;
from imblearn import under_sampling, over_sampling
I am getting the following error;
<ipython-input-36-d0524665b8f2> in <module>()
----> 1 from imblearn import under_sampling, over_sampling
~/anaconda3/lib/python3.6/site-packages/imblearn/under_sampling/__init__.py in <module>()
4 """
5
----> 6 from .prototype_generation import ClusterCentroids
7
8 from .prototype_selection import RandomUnderSampler
~/anaconda3/lib/python3.6/site-packages/imblearn/under_sampling/prototype_generation/__init__.py in <module>()
4 """
5
----> 6 from .cluster_centroids import ClusterCentroids
7
8 __all__ = [
~/anaconda3/lib/python3.6/site-packages/imblearn/under_sampling/prototype_generation/cluster_centroids.py in <module>()
12 from scipy import sparse
13
---> 14 from sklearn.cluster import KMeans
15 from sklearn.neighbors import NearestNeighbors
16 from sklearn.utils import safe_indexing
~/anaconda3/lib/python3.6/site-packages/sklearn/cluster/__init__.py in <module>()
4 """
5
----> 6 from .spectral import spectral_clustering, SpectralClustering
7 from .mean_shift_ import (mean_shift, MeanShift,
8 estimate_bandwidth, get_bin_seeds)
~/anaconda3/lib/python3.6/site-packages/sklearn/cluster/spectral.py in <module>()
15 from ..metrics.pairwise import pairwise_kernels
16 from ..neighbors import kneighbors_graph
---> 17 from ..manifold import spectral_embedding
18 from .k_means_ import k_means
19
~/anaconda3/lib/python3.6/site-packages/sklearn/manifold/__init__.py in <module>()
4
5 from .locally_linear import locally_linear_embedding, LocallyLinearEmbedding
----> 6 from .isomap import Isomap
7 from .mds import MDS, smacof
8 from .spectral_embedding_ import SpectralEmbedding, spectral_embedding
~/anaconda3/lib/python3.6/site-packages/sklearn/manifold/isomap.py in <module>()
9 from ..utils import check_array
10 from ..utils.graph import graph_shortest_path
---> 11 from ..decomposition import KernelPCA
12 from ..preprocessing import KernelCenterer
13
~/anaconda3/lib/python3.6/site-packages/sklearn/decomposition/__init__.py in <module>()
9 from .incremental_pca import IncrementalPCA
10 from .kernel_pca import KernelPCA
---> 11 from .sparse_pca import SparsePCA, MiniBatchSparsePCA
12 from .truncated_svd import TruncatedSVD
13 from .fastica_ import FastICA, fastica
~/anaconda3/lib/python3.6/site-packages/sklearn/decomposition/sparse_pca.py in <module>()
9 from ..utils import check_random_state, check_array
10 from ..utils.validation import check_is_fitted
---> 11 from ..linear_model import ridge_regression
12 from ..base import BaseEstimator, TransformerMixin
13 from .dict_learning import dict_learning, dict_learning_online
~/anaconda3/lib/python3.6/site-packages/sklearn/linear_model/__init__.py in <module>()
10 # complete documentation.
11
---> 12 from .base import LinearRegression
13
14 from .bayes import BayesianRidge, ARDRegression
~/anaconda3/lib/python3.6/site-packages/sklearn/linear_model/base.py in <module>()
25
26 from ..externals import six
---> 27 from ..utils import Parallel, delayed
28 from ..base import BaseEstimator, ClassifierMixin, RegressorMixin
29 from ..utils import check_array, check_X_y
ImportError: cannot import name 'Parallel
Can anyone please guide me?
Thanks!
So it worked after I installed SMOTE using the following steps;
pip install -U imbalanced-learn
conda install -c conda-forge imbalanced-learn
Looks like I was installing it incorrectly.
I am not able to understand the errors in the previous installation.Would appreciate if someone could point those out to me.
Thanks!
Thanks, I have the same issue, but I ran the following command in terminal or command prompt to fix the issue.
pip install -U imbalanced-learn
after its successfull execution i ran following conda command
conda install -c conda-forge imbalanced-learn
that's how i fixed my problem
Adding these comments as an answer at the suggestion of joanis:
A convenient way to install packages to the same environment backing a Jupyter notebook is to use the modern magic commands for pip and conda in cells in the notebook. The magic commands %pip install <package name> and %conda install <package name> were added to make sure the installs done inside a Jupyter notebook get placed in the actual environment that backs the notebook, see here for more information. The use of the exclamation point alone in front of pip or conda wasn't capable of insuring installation to the proper backing environment, and this often lead to issues of users not understanding why they couldn't import properly after they thought they had installed following the advice of others.
(The % symbol will work in front of pip and conda for other commands besides installs, and so it is just easiest to think of best practice for the use of pip and conda inside Jupyter notebooks now as %pip ... or %conda ..., where ... represents the rest of the command.)
Because in most modern Jupyter systems automagics are enabled by default, you can actually leave off the symbol in front of pip or conda and get the modern magic commands used behind-the-scenes as well. Although it is often best to use the explicit % symbol so that you and others are more aware of what is happening.

IPython fails to import Geopandas

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.

Categories

Resources