Search code examples
pythonpython-3.xopenstreetmaposmnx

How to install osmnx in Python?


I am trying to use osm library in Python. I found a recommended package called osmnx. I installed it via the command:

python -m pip install osmnx

when I type:

py -m pip freeze

I receive:

click==7.1.2
cycler==0.10.0
Flask==1.1.2
Flask-Ext==0.1
Flask-SQLAlchemy==2.4.4
itsdangerous==1.1.0
Jinja2==2.11.3
kiwisolver==1.3.1
MarkupSafe==1.1.1
matplotlib==3.3.4
numpy==1.20.1
osm==1.4
overpy==0.4
Pillow==8.1.0
pyparsing==2.4.7
python-dateutil==2.8.1
six==1.15.0
SQLAlchemy==1.3.23
Werkzeug==1.0.1

but osmnx is never there. Consequently when I run the code posted below, I receive the following error:

Traceback (most recent call last):
  File "m:\python lessons\flask apps\osm\osmnx\test.py", line 1, in <module>
    import osmnx as ox
ModuleNotFoundError: No module named 'osmnx'

Please let me know how to install osmnx in Python. code:

import osmnx as ox
import matplotlib.pyplot as plt

place_name = "Kamppi, Helsinki, Finland"
graph = ox.graph_from_place(place_name)

Solution

  • I'm using OSMX inside of Blender which comes with its own Python distribution and Blender doesn't work well with Conda's python installs (Blender has its own python requirements). I got OSMX installed via Conda, but then Blender starting giving me all sorts of errors when using the Conda environment even following the suggestions on how to get Conda to work with Blender.

    What I did is install all dependencies via pip, mindful of which version is the prereq as what is already installed may not be the version OSMX needs.

    Then I installed OSMX via pip using a local wheel download from https://pypi.org/project/osmnx/#files (installing direct only had an old version and gave installation errors).

    On Windows,

     .\python -m pip install osmnx-1.3.0-py3-none-any.whl
    

    After installing the pre-reqs, the wheel installed with no errors. If you have a dependency that isn't met - it will tell you and what specific version is needed.

    In my case, while I had Shapely installed from another package, OSMX wanted 2.0 so I had to upgrade it using

    .\python -m pip install shapely --upgrade
    

    Hope this helps,

    M