Error in importing geopandas - python

I am getting the following error when importing
import geopandas as gpd
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-f8b81fe8ca07> in <module>()
----> 1 import geopandas as gpd
//anaconda/lib/python2.7/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/python2.7/site-packages/geopandas/io/file.py in <module>()
1 import os
2
----> 3 import fiona
4 import numpy as np
5 from shapely.geometry import mapping
//anaconda/lib/python2.7/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/python2.7/site-packages/fiona/collection.py in <module>()
6 import warnings
7
----> 8 from fiona import compat
9 from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
10 from fiona.ogrext import Session, WritingSession
ImportError: cannot import name compat
I have installed geoPandas using anaconda however when I am trying to run it is displaying me the above error. When running
conda list
I am getting
After the runnning of the following:
conda install -c conda-forge fiona shapely pyproj rtree
conda install pandas
conda install -c conda-forge geopandas
I am getting
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-f8b81fe8ca07> in <module>()
----> 1 import geopandas as gpd
//anaconda/lib/python2.7/site-packages/geopandas/__init__.pyc 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/python2.7/site-packages/geopandas/io/file.py in <module>()
1 import os
2
----> 3 import fiona
4 import numpy as np
5 from shapely.geometry import mapping
//anaconda/lib/python2.7/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/python2.7/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/python2.7/site-packages/fiona/ogrext.so,
2): Library not loaded: #rpath/libnetcdf.11.dylib
Referenced from: //anaconda/lib/libgdal.20.dylib
Reason: Incompatible library version: libgdal.20.dylib requires version
12.0.0 or later, but libnetcdf.11.dylib provides version 11.0.0

The problem is caused by incompatibility of the fiona's and gdal's dependencies. Uninstall geopandas via conda. It will uninstall fiona as well.
Do conda uninstall geopandas;
Do conda install fiona=1.6
Do conda search fiona before hand and see if it is available for your version of python. If not, create new environment for that version of python.(Ex. create -n py35 python=3.5 anaconda)
Then pip install geopandas
Finally, try to import geopandas and see if you still get the error.

I had the same issue in MacOs Mojave 10.14. I found out that the solution is to install geopandas via pip instead of using conda
pip install geopandas

Related

OSError: Could not load shared object file: llvmlite.dll (SHAP related. What could be missing?)

I want to use SHAP with Anaconda.
Prequisites:
llvmlite is installed:
pip install llvmlite
Requirement already satisfied: llvmlite in c:\users...\anaconda3\lib\site-packages (0.34.0)
However, I get the error message in the supject, that llvmlite.dll could not be loaded:
from sklearn.model_selection import train_test_split
import xgboost
import shap
import numpy as np
import matplotlib.pylab as pl
​
# print the JS visualization code to the notebook
shap.initjs()
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-1-1cffb01788c0> in <module>
1 from sklearn.model_selection import train_test_split
2 import xgboost
----> 3 import shap
4 import numpy as np
5 import matplotlib.pylab as pl
~\Anaconda3\lib\site-packages\shap\__init__.py in <module>
10 warnings.warn("As of version 0.29.0 shap only supports Python 3 (not 2)!")
11
---> 12 from ._explanation import Explanation
13
14 # explainers
~\Anaconda3\lib\site-packages\shap\_explanation.py in <module>
8 from slicer import Slicer, Alias
9 # from ._order import Order
---> 10 from .utils._general import OpChain
11
12 # slicer confuses pylint...
~\Anaconda3\lib\site-packages\shap\utils\__init__.py in <module>
----> 1 from ._clustering import hclust_ordering, partition_tree, partition_tree_shuffle, delta_minimization_order, hclust
2 from ._general import approximate_interactions, potential_interactions, sample, safe_isinstance, assert_import, record_import_error
3 from ._general import shapley_coefficients, convert_name, format_value, ordinal_str, OpChain
4 from ._show_progress import show_progress
5 from ._masked_model import MaskedModel, make_masks
~\Anaconda3\lib\site-packages\shap\utils\_clustering.py in <module>
2 import scipy as sp
3 from scipy.spatial.distance import pdist
----> 4 from numba import jit
5 import sklearn
6 import warnings
~\Anaconda3\lib\site-packages\numba\__init__.py in <module>
12 del get_versions
13
---> 14 from numba.core import config
15 from numba.testing import _runtests as runtests
16 from numba.core import types, errors
~\Anaconda3\lib\site-packages\numba\core\config.py in <module>
14
15
---> 16 import llvmlite.binding as ll
17
18 IS_WIN32 = sys.platform.startswith('win32')
~\Anaconda3\lib\site-packages\llvmlite\binding\__init__.py in <module>
2 Things that rely on the LLVM library
3 """
----> 4 from .dylib import *
5 from .executionengine import *
6 from .initfini import *
~\Anaconda3\lib\site-packages\llvmlite\binding\dylib.py in <module>
1 from ctypes import c_void_p, c_char_p, c_bool, POINTER
2
----> 3 from llvmlite.binding import ffi
4 from llvmlite.binding.common import _encode_string
5
~\Anaconda3\lib\site-packages\llvmlite\binding\ffi.py in <module>
151 break
152 else:
--> 153 raise OSError("Could not load shared object file: {}".format(_lib_name))
154
155
OSError: Could not load shared object file: llvmlite.dll
Does anybody have an idea what the root cause may be and whatelse I could try?
THx,
Marcus
I did both
conda uninstall llvmlite
pip install llvmlite
and
conda uninstall llvmlite
conda install llvmlite
but can't get it work.
I got it work with
conda install -c numba numba
conda install -c numba llvmlite
in my case, following actions worked:
conda uninstall llvmlite
and then
conda install llvmlite
I had the same llvmlite missing DLL issue on Windows 10 with Python 3.8 in jupyter notebook when trying to import numba and solved it by installing with pip instead of conda :
conda uninstall llvmlite
pip install llvmlite
If it still does not wortk try installing llvmlite from wheel by downloading your wheel on this page :
https://www.lfd.uci.edu/~gohlke/pythonlibs/#llvmlite
pip install llvmlite-0.34.0-cp38-cp38-win_amd64.whl (replace with your wheel)
You need VC runtime to use Llvmlite
Llvmlite: a lightweight LLVM binding for writing JIT compilers.
Requires the Visual C++ Redistributable Packages for Visual Studio 2017.
check this https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170
or for x64 direct link:
https://aka.ms/vs/17/release/vc_redist.x64.exe

How to install python package 'rpy2' in Databricks?

I am trying to install and utilize pymer4 package functionalities in Databricks which requires rpy2 to be installed as well. Under Library in the Cluster I am able to install them, it even says "Installed", but when I try to import them then it gives error, as if it was not installed properly. In local system it works perfectly.
from pymer4.test_install import test_install
Error is:
ImportError: No module named 'pandas.core.dtypes'
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<command-2946392196605768> in <module>()
----> 1 from pymer4.test_install import test_install
/databricks/python/lib/python3.5/site-packages/pymer4/__init__.py in <module>()
6 "__version__"]
7
----> 8 from .models import Lmer, Lm
9 from .simulate import (easy_multivariate_normal,
10 simulate_lm,
/databricks/python/lib/python3.5/site-packages/pymer4/models.py in <module>()
2 import rpy2.robjects as robjects
3 from rpy2.robjects.packages import importr
----> 4 from rpy2.robjects import pandas2ri
5 import rpy2
6 from copy import copy
/databricks/python/lib/python3.5/site-packages/rpy2/robjects/pandas2ri.py in <module>()
14 from pandas.core.series import Series as PandasSeries
15 from pandas.core.index import Index as PandasIndex
---> 16 from pandas.core.dtypes.api import is_datetime64_any_dtype
17 import pandas
18 import numpy
ImportError: No module named 'pandas.core.dtypes'
Was able to solve my own problem. It was nothing but version issues of dependent packages of pymer4 package.
Changed the version of following packages with the latest one prior to release date of pymer4 and it worked:
matplotlib==3.0.2
pandas==0.23.4
rpy2==2.9.4
tzlocal

Installing Geopandas undoes Jupyter installation

I installed qtconsole using conda and the command conda install qtconsole. Then I was able to open up the console by typing the following command
jupyter qtconsole
Later on I found that I needed the geopandas package and I installed it by doing:
conda install geopandas
This however broke the qtconsole installation such that when I type in jupyter qtconsole in cmd no console appears. Then I thought I would update qtconsole to bring it back by doing conda update qtconsole. This worked (ie I got the console to work again). However when I try to import the geopandas package in it I get the error
ImportError
Traceback (most recent call last)
<ipython-input-1-fc7d1d298f0c in <module ()
----> 1 import geopandas
~\AppData\Local\Continuum\miniconda3\envs\mynewenv\lib\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
~\AppData\Local\Continuum\miniconda3\envs\mynewenv\lib\site-packages\geopandas\io\file.py
in <module ()
1 import os
2
----> 3 import fiona
4 import numpy as np
5 import six
~\AppData\Local\Continuum\miniconda3\envs\mynewenv\lib\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
~\AppData\Local\Continuum\miniconda3\envs\mynewenv\lib\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: DLL load failed: The specified module could not be found.
It seems like qtconsole cannot coexist with geopandas. This seems strange. How do I fix this?

ImportError: No module named 'tensorflow.python' with tensorflow-gpu

I wanted to have gpu-support for keras/tensorflow, thats why I installed tensorflow-gpu.
So I installed tensorflow-gpu through pip:
pip install --upgrade tensorflow-gpu
This leads to this:
from keras import backend as K
K.tensorflow_backend._get_available_gpus()
> []
Then I found this stackoverflow answer which stated I should uninstall tensorflow after installing tensorflow-gpu. This leads to this:
Using TensorFlow backend.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-3d00d838479b> in <module>()
----> 1 from keras import backend as K
2 K.tensorflow_backend._get_available_gpus()
/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/__init__.py in <module>()
1 from __future__ import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications
/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/utils/__init__.py in <module>()
4 from . import data_utils
5 from . import io_utils
----> 6 from . import conv_utils
7
8 # Globally-importable utils.
/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/utils/conv_utils.py in <module>()
7 from six.moves import range
8 import numpy as np
----> 9 from .. import backend as K
10
11
/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/backend/__init__.py in <module>()
82 elif _BACKEND == 'tensorflow':
83 sys.stderr.write('Using TensorFlow backend.\n')
---> 84 from .tensorflow_backend import *
85 else:
86 raise ValueError('Unknown backend: ' + str(_BACKEND))
/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/backend/tensorflow_backend.py in <module>()
4
5 import tensorflow as tf
----> 6 from tensorflow.python.training import moving_averages
7 from tensorflow.python.ops import tensor_array_ops
8 from tensorflow.python.ops import control_flow_ops
ImportError: No module named 'tensorflow.python'
Reeinstalling tensorflow with
pip install --upgrade tensorflow --no-cache
leads again to an empty array for the gpus with the code above.
Any ideas how to fix this?
This solution worked for me:
Uninstalling both CPU and GPU versions of TensorFlow and then installing only the GPU version of TensorFlow.
pip uninstall tensorflow
pip uninstall tensorflow-gpu
pip install tensorflow-gpu

Why can't I import folium python package?

I've pip installed folium and get this error when I try to import it in when Im working in my home directory:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-af6e4f19ef00> in <module>()
----> 1 import folium
//anaconda/lib/python2.7/site-packages/folium-0.3.0.dev0- py2.7.egg/folium/__init__.py in <module>()
3 from __future__ import absolute_import
4
----> 5 from folium.folium import Map, initialize_notebook, CircleMarker
6
7 from folium.map import (FeatureGroup, FitBounds, Icon, LayerControl, Marker,
//anaconda/lib/python2.7/site-packages/folium-0.3.0.dev0- py2.7.egg/folium/folium.py in <module>()
13 import json
14
---> 15 from branca.colormap import StepColormap
16 from branca.utilities import color_brewer
17 from branca.six import text_type, binary_type
ImportError: No module named branca.colormap
However, i can import it when I cd to /Library/Python/2.7/site-packages.... What gives?
Did you install the package with Anaconda? It looks like it's reading the package from Anaconda python's package install locations. A few things to try:
conda install branca
pip install branca

Categories