Toblerity/rtree

OSError: OSError: could not find or load spatialindex_c-64.dll

msaifp opened this issue · 7 comments

File "CSV_to_Shapefile_Converter.py", line 11, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "geopandas_init
.py", line 1, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "geopandas_config.py", line 126, in
File "geopandas_config.py", line 112, in _default_use_pygeos
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "geopandas_compat.py", line 202, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "rtree_init
.py", line 9, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "rtree\index.py", line 6, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "rtree\core.py", line 75, in
File "rtree\finder.py", line 67, in load
OSError: could not find or load spatialindex_c-64.dll
[2904] Failed to execute script 'CSV_to_Shapefile_Converter' due to unhandled exception!

Hi, this error has been driving me nuts for weeks now. I can't seem to resolve this issue as I've tried all solutions on the web - particularly those detailed in the Geopandas forums (#1812). Any help to resolve this issue would be greatly appreciated!

I had the very same problem when installing rtree from the conda-forge channel...
Uninstalling the previous version and using conda install rtree (without conda-forge) solved it for me!

@msaifp how did you install rtree?

@msaifp how did you install rtree?

Hey @mwtoews, sorry for the late reply. I installed everything using conda-forge. I just made a new environment and it was working fine.

I'm having the exact same error after creating a brand new blank environment. Here's the traceback of the error:

>>> import rtree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\____\.conda\envs\gpd\lib\site-packages\rtree\__init__.py", line 1, in <module>
    from .index import Rtree
  File "C:\Users\____\.conda\envs\gpd\lib\site-packages\rtree\index.py", line 6, in <module>
    from . import core
  File "C:\Users\____\.conda\envs\gpd\lib\site-packages\rtree\core.py", line 128, in <module>
    raise OSError("could not find or load %s" % lib_name)
OSError: could not find or load spatialindex_c-64.dll

I created a brand new environment using the following command:

conda create -n gpd python=3.8

Once the new environment was created, I activated it and installed rtree from the conda-forge channel as follows:

(gpd) conda install rtree=0.9.3 -c conda-forge

The installation went perfectly fine. However, when I boot up a Python session and try to import rtree, the I get error pasted at the top of my post.

Here's a full copy-paste of my steps:

D:\temp\geopandas>conda create -n gpd python=3.8
WARNING: A directory already exists at the target location 'C:\Users\____\.conda\envs\gpd'
but it is not a conda environment.
Continue creating environment (y/[n])? y

Collecting package metadata (repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.9.2
  latest version: 4.11.0

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: C:\Users\____\.conda\envs\gpd

  added / updated specs:
    - python=3.8


The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/win-64::ca-certificates-2021.10.26-haa95532_2
  certifi            pkgs/main/win-64::certifi-2021.10.8-py38haa95532_2
  openssl            pkgs/main/win-64::openssl-1.1.1m-h2bbff1b_0
  pip                pkgs/main/win-64::pip-21.2.2-py38haa95532_0
  python             pkgs/main/win-64::python-3.8.12-h6244533_0
  setuptools         pkgs/main/win-64::setuptools-58.0.4-py38haa95532_0
  sqlite             pkgs/main/win-64::sqlite-3.37.0-h2bbff1b_0
  vc                 pkgs/main/win-64::vc-14.2-h21ff451_1
  vs2015_runtime     pkgs/main/win-64::vs2015_runtime-14.27.29016-h5e58377_2
  wheel              pkgs/main/noarch::wheel-0.37.1-pyhd3eb1b0_0
  wincertstore       pkgs/main/win-64::wincertstore-0.2-py38haa95532_2


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate gpd
#
# To deactivate an active environment, use
#
#     $ conda deactivate


D:\temp\geopandas>activate gpd

D:\temp\geopandas>conda.bat activate gpd

(gpd) D:\temp\geopandas>conda install rtree=0.9.3 -c conda-forge
Collecting package metadata (repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.9.2
  latest version: 4.11.0

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: C:\Users\____\.conda\envs\gpd

  added / updated specs:
    - rtree=0.9.3


The following NEW packages will be INSTALLED:

  libspatialindex    conda-forge/win-64::libspatialindex-1.9.3-h39d44d4_4
  python_abi         conda-forge/win-64::python_abi-3.8-2_cp38
  rtree              conda-forge/win-64::rtree-0.9.3-py38hbf79ddb_0

The following packages will be SUPERSEDED by a higher-priority channel:

  ca-certificates    pkgs/main::ca-certificates-2021.10.26~ --> conda-forge::ca-certificates-2021.10.8-h5b45459_0
  certifi            pkgs/main::certifi-2021.10.8-py38haa9~ --> conda-forge::certifi-2021.10.8-py38haa244fe_1
  openssl              pkgs/main::openssl-1.1.1m-h2bbff1b_0 --> conda-forge::openssl-1.1.1l-h8ffe710_0


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

(gpd) D:\temp\geopandas>python
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rtree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\____\.conda\envs\gpd\lib\site-packages\rtree\__init__.py", line 1, in <module>
    from .index import Rtree
  File "C:\Users\____\.conda\envs\gpd\lib\site-packages\rtree\index.py", line 6, in <module>
    from . import core
  File "C:\Users\____\.conda\envs\gpd\lib\site-packages\rtree\core.py", line 128, in <module>
    raise OSError("could not find or load %s" % lib_name)
OSError: could not find or load spatialindex_c-64.dll
>>

Hmmm... I just tried another approach and it seemed to work.

Instead of installing python from main conda channel, I just created a blank environment as follows:

conda create -n gpd

Then, once the new environment is activated, I install rtree from the conda-forge channel:

(gpd) conda install rtree=0.9.3 -c conda-forge

Once that's done, I can just import rtree without any issues. I'm not exactly sure why this route works, but if I had to guess, I'd say it's related to the version of Python and its interaction with the libspatialindex library.

When I requested Python to be installed into a new environment, the version it installed was:

pkgs/main/win-64::python-3.8.12-h6244533_0

However, when I created a blank (Python-less) environment and told conda to install rtree from conda-forge, it pulled the following python version:

conda-forge/win-64::python-3.8.12-h900ac77_2_cpython

I think there's something funky going on with that cpython tag at the end of the python version.

I have used pip and its still not working for me

hobu commented

Can you grab a wheel from the build artifacts of #206 for your platform and verify that it works for you?