0

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)
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • Did you read the OSMnx documentation? It provides specific installation instructions. https://osmnx.readthedocs.io/en/stable/ Question may be a dupe of https://stackoverflow.com/a/62958055/7321942 – gboeing Mar 01 '21 at 21:28

5 Answers5

1

Try install with conda:

conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx

https://osmnx.readthedocs.io/en/stable/

0

Just to add to this, if you have installed osmnx using the above instructions , you will need to activate the environment each time you want to use it. To do this in anaconda prompt, type the following:

conda activate ox

This takes you from the base environment to the ox environment. You will then be able to execute the above code in anaconda prompt by typing

python myprogram.py

where myprogram.py is the name of your python program.

Older versions of osmnx installed into the base environment. However, this is not the case anymore it seems. I think there were some issues with package clashes or something.

Rhyd Lewis
  • 59
  • 4
-1

If you want to install osnmx without conda try these steps:

  1. From the OSMnx Github repo get the latest requirements.txt file

  2. Install all requirements with pip command:
    python3 -m pip install -r requirements.txt

  3. Install osmnx with pip while all modules are satisfied:
    python3 -m pip install osmnx

Community
  • 1
  • 1
Iman
  • 410
  • 7
  • 17
-1

You can find the answer in Installing OSMnx on Windows by Joshua Kobina Obeng article.

I will inlude the stesps as it is easy for you to see.

  1. Open Anaconda command prompt(base) and type the following commands.

conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx
  1. Then activate the enironment according to the instructions shown on the command prompt.

  2. Open Anaconda Navigator.

  3. In the "applications on" drop down, select "ox".

  4. Instll Jupyter notebook by click on th install button given under "Jupyter Notebook".

  5. After instllation complleted, launch Jupyter Notebook.

  6. Open notebook and import osmnx.

Hiruni K
  • 169
  • 2
  • 9
-1

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

EMCS
  • 144
  • 2
  • 1