Łukasz Janiec
04/17/2025, 12:09 PMdef get_shortest_path(
G: nx.MultiDiGraph, origin: tuple[float, float], destination: tuple[float, float]
) -> list[tuple[int, int]]:
"""
Get the shortest path between two points in the graph.
:param G: The road network graph.
:param origin: The (latitude, longitude) of the origin.
:param destination: The (latitude, longitude) of the destination.
:return: list of edges in the shortest path.
"""
orig_node = ox.distance.nearest_nodes(G, origin[1], origin[0])
dest_node = ox.distance.nearest_nodes(G, destination[1], destination[0])
shortest_path = nx.shortest_path(G, orig_node, dest_node, weight="length")
path_edges = list(zip(shortest_path[:-1], shortest_path[1:]))
return path_edges
But it becomes a problem when I am trying to use it with CLI `kedro run`:
UserWarning: An error occurred while importing the
'networking_route_optimizer.pipelines.data_ingestion' module. Nothing defined therein will be
returned by 'find_pipelines'.
Traceback (most recent call last):
File "/home/ljaniec/.local/lib/python3.10/site-packages/kedro/framework/project/__init__.py", line
442, in find_pipelines
pipeline_module = importlib.import_module(pipeline_module_name)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name, package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File
"/home/ljaniec/workspace/networking-route-optimizer/src/networking_route_opti
mizer/pipelines/data_ingestion/__init__.py", line 1, in <module>
from .pipeline import create_pipeline # NOQA
File
"/home/ljaniec/workspace/networking-route-optimizer/src/networking_route_opti
mizer/pipelines/data_ingestion/pipeline.py", line 3, in <module>
from networking_route_optimizer.pipelines.data_ingestion.nodes import (
File
"/home/ljaniec/workspace/networking-route-optimizer/src/networking_route_opti
mizer/pipelines/data_ingestion/nodes.py", line 3, in <module>
import osmnx as ox
ModuleNotFoundError: No module named 'osmnx'
warnings.warn(
What is the problem there? I know that OSMNx standard installation uses conda
and I installed it with pip
, but I would expect this to be a problem both in script and in the pipeline...Nok Lam Chan
04/17/2025, 12:28 PMimport osmnx
, does it import successfully?Łukasz Janiec
04/17/2025, 12:28 PMNok Lam Chan
04/17/2025, 12:28 PMwhich kedro
, see if it matches your virtual env. Sometimes terminal does caching on executable so you need to restart the terminal or run some commandNok Lam Chan
04/17/2025, 12:29 PMpython -m kedro run
to make sure it's using the correct python interpreterNok Lam Chan
04/17/2025, 12:30 PMhash -rto reload the path
Łukasz Janiec
04/17/2025, 12:31 PM(networking) ljaniec@ljaniec-PC:~/workspace/networking-route-optimizer$ python
Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import osmnx
/home/ljaniec/workspace/networking-route-optimizer/venv/lib/python3.10/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.17.3 and <1.25.0 is required for this version of SciPy (detected version 2.2.4
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ljaniec/workspace/networking-route-optimizer/venv/lib/python3.10/site-packages/osmnx/__init__.py", line 14, in <module>
from .distance import nearest_edges as nearest_edges
File "/home/ljaniec/workspace/networking-route-optimizer/venv/lib/python3.10/site-packages/osmnx/distance.py", line 22, in <module>
from scipy.spatial import cKDTree
File "/home/ljaniec/workspace/networking-route-optimizer/venv/lib/python3.10/site-packages/scipy/spatial/__init__.py", line 102, in <module>
from ._kdtree import *
File "/home/ljaniec/workspace/networking-route-optimizer/venv/lib/python3.10/site-packages/scipy/spatial/_kdtree.py", line 5, in <module>
from ._ckdtree import cKDTree, cKDTreeNode
File "_ckdtree.pyx", line 1, in init scipy.spatial._ckdtree
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
>>> quit()
Łukasz Janiec
04/17/2025, 12:32 PMpython -m kedro run
Nok Lam Chan
04/17/2025, 12:34 PMNok Lam Chan
04/17/2025, 12:34 PMnumpy
scipy
packagesŁukasz Janiec
04/17/2025, 12:35 PMŁukasz Janiec
04/17/2025, 12:37 PMNok Lam Chan
04/17/2025, 1:20 PMpython -m
is a good trick to check, sometimes pip
has the same problem