[英]" could not find or load spatialindex_c.dll" in windows?
system:windows系统:windows
versions:python 3.6版本:python 3.6
I successfully install osmnx and Rtree.我成功安装了 osmnx 和 Rtree。 But still have error.但是还是有错误。
My code:我的代码:
> import osmnx as ox
> from Ipython.display import Image
> ox.config(log_file=True,log_console=True,use_cache=True)
>
> img_folder='image'; extension='png'; size=700
>
> place='shanghai' point=(121.48,31.22) >
> fig,ax=ox.plot_figure_ground(point=point,filename=place,network_type='all',dpi=150)
> Image('{}/{}.{}'.fromat(img_folder,place,extension),height=size,width=size)
raise OSError("could not find or load spatialindex_c.dll")引发 OSError("无法找到或加载空间索引_c.dll")
OSError: could not find or load spatialindex_c.dll OSError: 无法找到或加载 spatialindex_c.dll
What does this mean, what causes it, and how should you fix it?这是什么意思,是什么原因造成的,你应该如何解决它?
If you're using conda, the easiest way to install OSMnx and avoid this issue is with conda-forge, as stated in the docs :如果您使用的是 conda,安装 OSMnx 并避免此问题的最简单方法是使用 conda-forge,如文档中所述:
conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx
Or you can run OSMnx (and Jupyter) directly from its official docker container .或者您可以直接从其官方 docker容器运行 OSMnx(和 Jupyter)。
It means that you only thought you had successfully installed osmnx or one of it's dependencies.这意味着您只认为您已经成功安装了 osmnx 或其依赖项之一。
Of course a lot depends on how you installed osmnx - when I tried with pip in a virtual environment it failed for me with:当然,很大程度上取决于您如何安装 osmnx - 当我在虚拟环境中尝试使用 pip 时,它失败了:
Collecting OSMnx
Downloading osmnx-0.5.3-py2.py3-none-any.whl (54kB)
100% |████████████████████████████████| 61kB 183kB/s
Collecting shapely>=1.5 (from OSMnx)
Downloading Shapely-1.6.0.tar.gz (214kB)
100% |████████████████████████████████| 215kB 2.0MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\STEVE-~1\AppData\Local\Temp\pip-build-9uqvlpcm\shapely\setup.py", line 80, in <module>
from shapely._buildcfg import geos_version_string, geos_version, \
File "C:\Users\STEVE-~1\AppData\Local\Temp\pip-build-9uqvlpcm\shapely\shapely\_buildcfg.py", line 200, in <module>
lgeos = CDLL("geos_c.dll")
File "C:\Python36_64\lib\ctypes\__init__.py", line 344, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\STEVE-~1\AppData\Local\Temp\pip-build-9uqvlpcm\shapely\
Going to http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely gave me a download for the python I was using 3.6 (64 bit) which I installed by downloading then using pip on the downloaded file.转到http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely给了我下载的 python 我使用的3.6(64 位) ,我通过下载然后在下载的文件上使用 pip 来安装它。
Re-running pip install OSMnx
my next problem was with the compilation of fiona so Chris Gohlke to the rescue again at http://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona which has a note "requires gdal" so I hopped to http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal while I was there and installed that first.重新运行pip install OSMnx
我的下一个问题是 fiona 的编译,所以 Chris Gohlke 再次在http://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona上进行救援,其中有一个注释“需要 gdal”所以我在那里时跳到http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal并先安装了它。
On running your first import I got:在运行您的第一次导入时,我得到了:
>>> import osmnx as ox
Traceback (most recent call last):
File "F:\toolbuild\test_OSMnx\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
ImportError: DLL load failed: The specified procedure could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:\toolbuild\test_OSMnx\lib\site-packages\osmnx\__init__.py", line 8, in <module>
from .buildings import *
File "F:\toolbuild\test_OSMnx\lib\site-packages\osmnx\buildings.py", line 9, in <module>
import geopandas as gpd
File "F:\toolbuild\test_OSMnx\lib\site-packages\geopandas\__init__.py", line 1, in <module>
from geopandas.geoseries import GeoSeries
File "F:\toolbuild\test_OSMnx\lib\site-packages\geopandas\geoseries.py", line 5, in <module>
import numpy as np
File "F:\toolbuild\test_OSMnx\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "F:\toolbuild\test_OSMnx\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "F:\toolbuild\test_OSMnx\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "F:\toolbuild\test_OSMnx\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "F:\toolbuild\test_OSMnx\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified procedure could not be found.
I had noticed that it seemed that numpy had installed correctly but I know that there can be issues with it so off to http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy where we find a note: "Numpy+MKL is linked to the Intel® Math Kernel Library and includes required DLLs in the numpy.core directory."我注意到 numpy 似乎已正确安装,但我知道它可能存在问题,因此我们可以在http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy中找到一个注释:“ Numpy+MKL 链接到英特尔® 数学内核库,并在 numpy.core 目录中包含所需的 DLL。” so again I download and install.所以我再次下载并安装。
Now I am at your stage of:现在我处于你的阶段:
> import osmnx as ox
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:\toolbuild\test_OSMnx\lib\site-packages\osmnx\__init__.py", line 8, in <module>
from .buildings import *
File "F:\toolbuild\test_OSMnx\lib\site-packages\osmnx\buildings.py", line 9, in <module>
import geopandas as gpd
File "F:\toolbuild\test_OSMnx\lib\site-packages\geopandas\__init__.py", line 1, in <module>
from geopandas.geoseries import GeoSeries
File "F:\toolbuild\test_OSMnx\lib\site-packages\geopandas\geoseries.py", line 16, in <module>
from geopandas.base import GeoPandasBase
File "F:\toolbuild\test_OSMnx\lib\site-packages\geopandas\base.py", line 15, in <module>
from rtree.core import RTreeError
File "F:\toolbuild\test_OSMnx\lib\site-packages\rtree\__init__.py", line 1, in <module>
from .index import Rtree
File "F:\toolbuild\test_OSMnx\lib\site-packages\rtree\index.py", line 5, in <module>
from . import core
File "F:\toolbuild\test_OSMnx\lib\site-packages\rtree\core.py", line 116, in <module>
raise OSError("could not find or load spatialindex_c.dll")
OSError: could not find or load spatialindex_c.dll
Looks like the problem is in RTree so off to http://www.lfd.uci.edu/~gohlke/pythonlibs/#rtree (note that this time we have to pip uninstall rtree
first)看起来问题出在 RTree 上,所以转到http://www.lfd.uci.edu/~gohlke/pythonlibs/#rtree (注意,这次我们必须先pip uninstall rtree
)
Trying your code, with a couple of line breaks added, again I get an error that the lat long limits are exceeded so swap the two values to set point=(31.22, 121.48)
and I get an image such as:尝试您的代码,添加了几个换行符,再次出现超出point=(31.22, 121.48)
限制的错误,因此将两个值交换为 set point=(31.22, 121.48)
然后我得到一个图像,例如:
from:来自:
>>> fig,ax=ox.plot_figure_ground(point=point,filename=place,network_type='all',dpi=150)
Projected the GeoDataFrame "geometry to project" to UTM-51 in 0.00 seconds
Projected the GeoDataFrame "geometry to project" to EPSG 4326 in 0.00 seconds
Created bounding box 966.0 meters in each direction from (31.22, 121.48): 31.228713053594067,31.211286934028642,121.49013858668467,121.46986147388169
Projected the GeoDataFrame "geometry to project" to UTM-51 in 0.00 seconds
Projected the GeoDataFrame "geometry to project" to EPSG 4326 in 0.00 seconds
Requesting network data within bounding box from API in 1 request(s)
Pausing 0.00 seconds before making API POST request
Posting to http://www.overpass-api.de/api/interpreter with timeout=180, "{'data': '[out:json][timeout:180];(way["highway"]["area"!~"yes"]["highway"!~"proposed|construction|abandoned|platform|raceway"]["service"!~"private"]["access"!~"private"](31.21128693,121.46986147,31.22871305,121.49013859);>;);out;'}"
Downloaded 480.6KB from www.overpass-api.de in 2.13 seconds
Saved response to cache file "cache/8c99e35743a557d7234621c6d3fd7139.json"
Got all network data within bounding box from API in 1 request(s) and 2.99 seconds
Creating networkx graph from downloaded OSM data...
Graph was not connected, retained only the largest weakly connected component (3,366 of 3,540 total nodes) in 0.15 seconds
Created graph with 3,366 nodes and 6,926 edges in 0.19 seconds
Added edge lengths to graph in 0.05 seconds
Truncated graph by bounding box in 0.14 seconds
Removed 0 isolated nodes
Graph was not connected, retained only the largest weakly connected component (2,764 of 2,779 total nodes) in 0.13 seconds
graph_from_bbox() returning graph with 2,764 nodes and 5,892 edges
graph_from_point() returning graph with 2,764 nodes and 5,892 edges
Begin topologically simplifying the graph...
Identified 1,568 edge endpoints in 0.04 seconds
Constructed all paths to simplify in 0.01 seconds
Simplified graph (from 2,764 to 1,568 nodes and from 5,892 to 3,730 edges) in 0.15 seconds
Created a GeoDataFrame from graph in 0.10 seconds
Projected the GeoDataFrame "unnamed_nodes" to UTM-51 in 0.07 seconds
Projected the GeoDataFrame "unnamed_edges" to UTM-51 in 0.29 seconds
Extracted projected node geometries from GeoDataFrame in 0.04 seconds
Rebuilt projected graph in 1.53 seconds
Projected the GeoDataFrame "geometry to project" to UTM-51 in 0.00 seconds
Created bounding box 805 meters in each direction from (31.22, 121.48) and projected it: 3455784.445871858,3454174.445871858,356022.8750159489,354412.8750159489
Begin plotting the graph...
Drew the graph edges in 0.05 seconds
Saved the figure to disk in 0.11 seconds
I had the same problem “could not find or load spatialindex_c.dll”
.我遇到了同样的问题“could not find or load spatialindex_c.dll”
。
What solved for me was pip uninstall rtree
.为我解决的是pip uninstall rtree
。 That's it.就是这样。 I am using conda
environment in a Windows 7 server without admin.我在没有管理员的 Windows 7 服务器中使用conda
环境。
Both osmnx
and geopandas
are present in my env
, which includes conda-forge
channel osmnx
和geopandas
都存在于我的env
,其中包括conda-forge
geopandas
频道
pip uninstall rtree pip卸载rtree
That worked for me那对我有用
I had the same error in Windows after installing rtree
with pip
and the wheel Rtree-0.9.7-cp39-cp39-win_amd64.whl
from Christoph Gohlke .使用pip
安装rtree
和Christoph Gohlke的车轮Rtree-0.9.7-cp39-cp39-win_amd64.whl
后,我在 Windows 中遇到了同样的错误。
I could see the error both executing import geopandas
or just opening spyder
.我可以看到执行import geopandas
或只是打开spyder
的错误。 In this case the error was a warning about missing dependencies rtree>= 0.9.7: None (NOK)
.在这种情况下,错误是关于缺少依赖rtree>= 0.9.7: None (NOK)
的警告rtree>= 0.9.7: None (NOK)
。
After inspecting the file finder.py
in the site-packages rtree
folder C:\\Users\\mysuer\\AppData\\Roaming\\Python\\Python39\\site-packages\\rtree
I saw this lines of code:检查文件后finder.py
在站点包rtree
文件夹C:\\Users\\mysuer\\AppData\\Roaming\\Python\\Python39\\site-packages\\rtree
我看到这个代码行:
# generate a bunch of candidate locations where the
# libspatialindex shared library *might* be hanging out
_candidates = [
os.environ.get('SPATIALINDEX_C_LIBRARY', None),
os.path.join(_cwd, 'lib'),
_cwd,
'']
So I found the rtree
folder where the libraries are located C:\\Users\\myuser\\AppData\\Roaming\\Python\\Lib\\site-packages\\rtree\\lib
and I created an environment variable targeting the folder.所以我找到了库所在的rtree
文件夹C:\\Users\\myuser\\AppData\\Roaming\\Python\\Lib\\site-packages\\rtree\\lib
并创建了一个针对该文件夹的环境变量。
Variable name变量名 | Variable value变量值 |
---|---|
SPATIALINDEX_C_LIBRARY |
C:\\Users\\myuser\\AppData\\Roaming\\Python\\Lib\\site-packages\\rtree\\lib |
Everything was fine after adding the environment variable.添加环境变量后一切正常。
The solution was to simply restart the Kernel in the Jupyter notebook.解决方案是简单地重新启动 Jupyter notebook 中的内核。 After installing some packages that use variables such as environment variables, these are only loaded when the kernel is (re-)started.安装一些使用环境变量等变量的软件包后,这些软件包仅在(重新)启动内核时加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.