Facing Import Error when importing esda and libpysal libraries - python

Even though I have installed both the libraries several times using different orders in different virtual environments, I'm still facing an issue where I'm not able to import and use certain geospatial libraries like esda and libpysal. The following error shows up:
ImportError Traceback (most recent call last)
C:\Users\SLAADM~1\AppData\Local\Temp/ipykernel_35328/2667884714.py in <module>
3 import numpy as np
4 import matplotlib.pyplot as plt
----> 5 import esda
6 import libpysal as lps
7 import pysal
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\esda\__init__.py in <module>
5
6 """
----> 7 from . import adbscan
8 from .gamma import Gamma
9 from .geary import Geary
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\esda\adbscan.py in <module>
8 import pandas
9 import numpy as np
---> 10 from libpysal.cg.alpha_shapes import alpha_shape_auto
11 from scipy.spatial import cKDTree
12 from collections import Counter
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\__init__.py in <module>
25 Tools for creating and manipulating weights
26 """
---> 27 from . import cg
28 from . import io
29 from . import weights
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\cg\__init__.py in <module>
9 from .sphere import *
10 from .voronoi import *
---> 11 from .alpha_shapes import *
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\cg\alpha_shapes.py in <module>
22
23 try:
---> 24 import pygeos
25
26 HAS_PYGEOS = True
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\pygeos\__init__.py in <module>
----> 1 from .lib import GEOSException # NOQA
2 from .lib import Geometry # NOQA
3 from .lib import geos_version, geos_version_string # NOQA
4 from .lib import geos_capi_version, geos_capi_version_string # NOQA
5 from .decorators import UnsupportedGEOSOperation # NOQA
ImportError: DLL load failed while importing lib: The specified procedure could not be found.
Would really appreciate any help in making this work. Please throw any suggestions you might have at me.

install pygeos i.e conda install pygeos
it worked for me

I found same issue when running example code from a couple of years ago. The pysal API has changed.
Import libpysal first then import the esda libraries eg
import libpysal
from esda.moran import Moran
from esda.smaup import Smaup
see
https://pysal.org/esda/generated/esda.Moran.html

Related

ImportError: cannot import name 'Sized' from 'collections'

I am trying to use one package that somebody developed on GitHub called PyLipid.
The first parts of the code are importing various packages, but I am continuously getting this error, showed bellow:
%matplotlib inline
import pylipid
import collections
from pylipid.api import LipidInteraction
# print(pylipid.__version__) # make sure pylipid version is later than 1.4
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Input In [37], in <cell line: 4>()
2 import pylipid
3 import collections
----> 4 from pylipid.api import LipidInteraction
File ~/miniconda3/envs/work/lib/python3.10/site-packages/pylipid/api/__init__.py:32, in <module>
1 ##############################################################################
2 # PyLipID: A python module for analysing protein-lipid interactions
3 #
(...)
14 # copies or substantial portions of the Software.
15 ##############################################################################
17 r"""
18 PyLipID class
19 =============
(...)
29
30 """
---> 32 from .api import LipidInteraction
File ~/miniconda3/envs/work/lib/python3.10/site-packages/pylipid/api/api.py:30, in <module>
28 import pandas as pd
29 from tqdm import trange, tqdm
---> 30 from p_tqdm import p_map
31 from ..func import cal_contact_residues
32 from ..func import Duration
File ~/miniconda3/envs/work/lib/python3.10/site-packages/p_tqdm/__init__.py:1, in <module>
----> 1 from p_tqdm.p_tqdm import p_map, p_imap, p_umap, p_uimap, t_map, t_imap
3 __all__ = [
4 'p_map',
5 'p_imap',
(...)
9 't_imap'
10 ]
File ~/miniconda3/envs/work/lib/python3.10/site-packages/p_tqdm/p_tqdm.py:11, in <module>
1 """Map functions with tqdm progress bars for parallel and sequential processing.
2
3 p_map: Performs a parallel ordered map.
(...)
8 t_imap: Returns an iterator for a sequential map.
9 """
---> 11 from collections import Sized
12 from typing import Any, Callable, Generator, Iterable, List
14 from pathos.helpers import cpu_count
ImportError: cannot import name 'Sized' from 'collections' (/home/srdjanm/miniconda3/envs/work/lib/python3.10/collections/__init__.py)
Does anybody know how to solve this error? I have also posted the question on the webpage in github but it might take a while for someone to respond, also this seems to me like a more general problem. Is this the package or "python version" related issue?
You may want to modify one line in the library to it works. It was created a pull request in github of p_tqdm library
In file ~/miniconda3/envs/work/lib/python3.10/site-packages/p_tqdm/p_tqdm.py modify line 11 from
from collections import Sized
to
from collections.abc import Sized

Scipy cannot import median_abs_deviation

I'm using a program called galpro which uses may packages, including scipy. When I use the command
import galpro as gp
I am then given the error:
ImportError Traceback (most recent call last)
<ipython-input-7-6eb7571a326c> in <module>
----> 1 import galpro as gp
~/galpro/galpro/__init__.py in <module>
----> 1 from .model import Model
~/galpro/galpro/model.py in <module>
8 import joblib
9 import h5py
---> 10 from .validation import Validation
11 from .plot import Plot
12 from .utils import convert_1d_arrays, create_directories
~/galpro/galpro/validation.py in <module>
2 import numpy as np
3 import h5py
----> 4 from .plot import Plot
5 from .utils import load_posteriors, create_templates
6 from .conf import set_plot_params
~/galpro/galpro/plot.py in <module>
4 import seaborn as sns
5 import statsmodels.api as sm
----> 6 from .utils import *
7 from .conf import set_plot_params
8
~/galpro/galpro/utils.py in <module>
3 import h5py
4 import numpy as np
----> 5 from scipy.stats import entropy, kstest, median_abs_deviation, cramervonmises
6
7
ImportError: cannot import name 'median_abs_deviation' ---------------------------------------------------------------------------
I have tried reinstalling scipy and this didn't help. According to documentation, the median_abs_deviation module should work with scipy 1.3.0 onwards, and I'm using 1.5.4. I have also tried reinstalling different versions of scipy and this has not helped either.

GluonCV ImportError: cannot import name 'is_np_array'

I'm trying to set up a GluonCV in a jupyter notebook in a virtual environment. For some reason whenever I try to import GluonCV I get this error:
ImportError Traceback (most recent call last)
<ipython-input-2-9a2bc396118f> in <module>
----> 1 import gluoncv
~\anaconda3\envs\mxnet\lib\site-packages\gluoncv\__init__.py in <module>
10 _require_mxnet_version('1.4.0', '2.0.0')
11
---> 12 from . import data
13 from . import model_zoo
14 from . import nn
~\anaconda3\envs\mxnet\lib\site-packages\gluoncv\data\__init__.py in <module>
29 from .sampler import SplitSampler, ShuffleSplitSampler
30 from .otb.tracking import OTBTracking
---> 31 from .kitti.kitti_dataset import KITTIRAWDataset, KITTIOdomDataset
32
33 datasets = {
~\anaconda3\envs\mxnet\lib\site-packages\gluoncv\data\kitti\__init__.py in <module>
1 # pylint: disable=missing-module-docstring
----> 2 from .kitti_dataset import *
3 from .kitti_utils import *
~\anaconda3\envs\mxnet\lib\site-packages\gluoncv\data\kitti\kitti_dataset.py in <module>
19
20 from ...utils.filesystem import try_import_skimage
---> 21 from .kitti_utils import generate_depth_map
22 from .mono_dataset import MonoDataset
23
~\anaconda3\envs\mxnet\lib\site-packages\gluoncv\data\kitti\kitti_utils.py in <module>
10
11 import mxnet as mx
---> 12 from mxnet.util import is_np_array
13
14
ImportError: cannot import name 'is_np_array'
I've tried using the same files that work on Google Collaboratory but I still get that error. I've tried reinstalling gluon and all that stuff in all manners. No idea what's going on. For convenience I really need this to work.
I resolved this error by installing the compatible versions of mxnet and gluoncv.In my case I had installed mxnet with with gluoncv native, that resolved the error.

i just want to import spacy but i get the msgpack error

ImportError Traceback (most recent call last)
<ipython-input-1-76a01d9c502b> in <module>
----> 1 import spacy
~\Anaconda3\envs\nlp_course\lib\site-packages\spacy\__init__.py in <module>
8 from thinc.neural.util import prefer_gpu, require_gpu
9
---> 10 from .cli.info import info as cli_info
11 from .glossary import explain
12 from .about import __version__
~\Anaconda3\envs\nlp_course\lib\site-packages\spacy\cli\__init__.py in <module>
----> 1 from .download import download
2 from .info import info
3 from .link import link
4 from .package import package
5 from .profile import profile
~\Anaconda3\envs\nlp_course\lib\site-packages\spacy\cli\download.py in <module>
9
10 from ._messages import Messages
---> 11 from .link import link
12 from ..util import prints, get_package_path
13 from .. import about
~\Anaconda3\envs\nlp_course\lib\site-packages\spacy\cli\link.py in <module>
7 from ._messages import Messages
8 from ..compat import symlink_to, path2str
----> 9 from ..util import prints
10 from .. import util
11
~\Anaconda3\envs\nlp_course\lib\site-packages\spacy\util.py in <module>
25 # Import these directly from Thinc, so that we're sure we always have the
26 # same version.
---> 27 from thinc.neural._classes.model import msgpack
28 from thinc.neural._classes.model import msgpack_numpy
29
ImportError: cannot import name 'msgpack' from 'thinc.neural._classes.model' (C:\Users\salwa\Anaconda3\envs\nlp_course\lib\site-packages\thinc\neural\_classes\model.py)
The problem is with thinc, a dependency of spaCy, as you can see here: ImportError: cannot import name 'msgpack' from 'thinc.neural._classes.model'
Follow Ines's (a core developer of spaCy) suggestion that you can find here,
It looks like you might have ended up with conflicting installationds
and dependencies – for example, the latest version of spaCy, but an
older version of its dependency, Thinc. In cases like this, it often
helps to just start out with a clean environment and reinstall from
scratch.

Unable to import modules from 'math' in Python

I've hit this weird issue were I'm unable to import from the math module in Python. However importing the entire module works.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/bdhammel/Documents/research_programming/analysis_routines/visar_analysis.py in <module>()
16
17 from core import scopes as cscopes
---> 18 from core import plot as cplot
19 from core.plot import ImageData, IndexSelector
20 from core.math import savitzky_golay
/Users/bdhammel/Documents/research_programming/core_diag/core/plot.py in <module>()
10 sys.path.append(CORE_DIR)
11
---> 12 from core import math as cmath
13
14 class ImageData(object):
/Users/bdhammel/Documents/research_programming/core_diag/core/math.py in <module>()
3 import sys
4 import math
----> 5 from math import factorial
6 from scipy.integrate import cumtrapz
7
ImportError: cannot import name factorial
My directory structure is something like this
Main file
from math import factorial # works fine here
import custom_module
custom_module
import math # works fine
from math import factorial # breaks
I have no idea why this could be. Any help would be appreciated.
I'm working inside of a virtual environment.
If you want to import the built-in math inside core.math, turn on absolute imports so you don't get core.math instead:
from __future__ import absolute_import

Categories