Ddee
Ddee

Reputation: 143

Issues running OSMnx on conda

I'm trying to get the Python package OSMnx running on my Windows10 machine. I'm still new to python so struggling with the basics. I've followed the instructions here https://osmnx.readthedocs.io/en/stable/ and have successfully created a new conda environment for it to run in. The installation seems to have gone ok. However, as soon as I try and import it, I get the following error

>>> import osmnx as ox
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\.conda\envs\ox\lib\site-packages\osmnx\__init__.py", line 3, in <module>
    from ._api import *
  File "C:\Users\User\.conda\envs\ox\lib\site-packages\osmnx\_api.py", line 4, in <module>
    from .distance import get_nearest_edge
  File "C:\Users\User\.conda\envs\ox\lib\site-packages\osmnx\distance.py", line 5, in <module>
    import networkx as nx
  File "C:\Users\User\.conda\envs\ox\lib\site-packages\networkx\__init__.py", line 114, in <module>
    import networkx.generators
  File "C:\Users\User\.conda\envs\ox\lib\site-packages\networkx\generators\__init__.py", line 14, in <module>
    from networkx.generators.intersection import *
  File "C:\Users\User\.conda\envs\ox\lib\site-packages\networkx\generators\intersection.py", line 13, in <module>
    from networkx.algorithms import bipartite
  File "C:\Users\User\.conda\envs\ox\lib\site-packages\networkx\algorithms\__init__.py", line 16, in <module>
    from networkx.algorithms.dag import *
  File "C:\Users\User\.conda\envs\ox\lib\site-packages\networkx\algorithms\dag.py", line 23, in <module>
    from fractions import gcd
ImportError: cannot import name 'gcd' from 'fractions' (C:\Users\User\.conda\envs\ox\lib\fractions.py)

I'm running with

   conda version : 4.8.2
   conda-build version : 3.18.11
   python version : 3.7.6.final.0

Is anyone able to advise me? Sorry if this is obvious, as I said I'm new to all this. Thank you

Upvotes: 3

Views: 769

Answers (2)

Laura.k.a
Laura.k.a

Reputation: 31

I am having the same problem. I installed all my packages using conda-forge (recommended install for OSMnx - https://osmnx.readthedocs.io/en/stable/). Conda-forge does not support package updates, if I understand correctly. Instead, remove networkx and reinstall, but be sure to specify version. You will need to reinstall osmnx too

conda remove -c conda-forge networkx
conda install -c conda-forge networkx=2.5
conda install -c conda-forge osmnx

Upvotes: 1

0 _
0 _

Reputation: 11534

The module fractions is part of the Python standard library. There used to be a function gcd, which, as the linked documentation says, is:

Deprecated since version 3.5: Use math.gcd() instead.

Since the function gcd was removed from the module fractions in Python 3.9, it seems that the question uses Python 3.9, not Python 3.7.6 as the question notes, because that Python version still had fractions.gcd.

The error is raised by networkx. Upgrading to the latest version of networkx is expected to avoid this issue:

pip install -U networkx

Indeed, the change that avoids this error from networkx is: https://github.com/networkx/networkx/commit/b007158f3bfbcf77c52e4b39a81061914788ddf9#diff-21e03bb1d46583650bcad6e960f2ab8a5397395c986942b59314033e963dd3fcL23, and has been released as part of networkx==2.4, networkx==2.5, and networkx==2.5.1, as the tags listed on the commit's GitHub page inform. The current line in networkx is: https://github.com/networkx/networkx/blob/d70b314b37168f0ea7c5b0d7f9ff61d73232747b/networkx/algorithms/dag.py#L9, i.e., from math import gcd.

Upvotes: 1

Related Questions