OSMnx gives "TypeError: query must be a string or a list of query strings" on basic use

OSMnx gives "TypeError: query must be a string or a list of query strings" on basic use

按照说明安装 OSMnx(包括显式安装 spatialindex)和

brew install spatialindex
pip install osmnx

运行宁

的第一个基本例子
import osmnx as ox
G = ox.graph_from_place('Manhattan Island, New York City, New York, USA', network_type='drive')
ox.plot_graph(ox.project_graph(G))

在项目的readme中,我得到

Traceback (most recent call last):
  File "/Users/Rax/Documents/Projects/Coding/Python/maps/test.py", line 23, in <module>
    G = ox.graph_from_place('Manhattan Island, New York City, New York, USA', network_type='drive')
  File "/usr/local/lib/python2.7/site-packages/osmnx/core.py", line 1850, in graph_from_place
    raise TypeError('query must be a string or a list of query strings')
TypeError: query must be a string or a list of query strings

如何让 OSMnx 运行 克服这个错误?

这可能是由于

from __future__ import unicode_literals

在您的代码中,since 包括它将所有字符串转换为 unicode 类型,而 API 需要 string 类型的参数。如果存在,将其删除将防止错误发生。

另请参阅:https://github.com/gboeing/osmnx/issues/185

OSMnx is compatible with Python 2 and 3, so you don't need to import from the future package to use it. If you use Python 2 and import unicode_literals from future, all of your strings will be of type unicode instead. As you can see in the documentation, graph_from_place expects the query to be of type string, not of type unicode.