Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing '__future__. unicode_literals' causes TypeError in 'graph_from_place' #185

Closed
orome opened this issue Jul 22, 2018 · 1 comment

Comments

@orome
Copy link

orome commented Jul 22, 2018

Problem description

After following the instructions for installation of OSMnx (including explicitly installing spatialindex ) with

brew install spatialindex
pip install osmnx

running the very first basic example of

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))

in the project's readme, I get

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

What operating system, architecture, Python version, and OSMnx version are you using?

macOS: 10.13.6 (17G65)
Python: 2.7.15
OSMnx: 0.8.1

Possible cause

I routinely begin my Python 2.7 code with

from __future__ import (absolute_import, print_function, division, unicode_literals)

and removing unicode_literals fixes the problem.

@gboeing
Copy link
Owner

gboeing commented Jul 22, 2018

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.

@gboeing gboeing closed this as completed Jul 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants