Pablo Suarez Beltran
Pablo Suarez Beltran

Reputation: 11

Osmnx ox.graph_from_place RuntimeError: b'no argument in initialization list'

I tried to run the demo, but no matter what I try I get RuntimeError: b'no arguments in initialization list' when I try to use ox.graph_from_place. I've search multiple places but haven't found any answers.I'm using windows 10, python 3.7 and my OSMNX version is 0.9.

Researching the problem I came across OSMnx graph_from_place #251, and I'm not quite sure how to "customize the environment to match the path on my own machine" as said at the bottom of the issue page, but it gave a link to installing OSMnx in a virtual environment. From there I tired uninstalling osmnx and conda install -c conda-forge osmnx (which works fine) as well as conda config --add channels conda-forge, and I also tried conda create --override-channels -c conda-forge -n OSMNX python=3 osmnx, but that gives me

Collecting package metadata: done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - osmnx -> geopandas -> fiona -> gdal[version='>=2.4.1,<2.5.0a0'] -> libgdal==2.4.1=h47faea2_1 -> m2w64-xz
  - osmnx -> geopandas -> fiona -> gdal[version='>=2.4.1,<2.5.0a0'] -> libgdal==2.4.1=h47faea2_1 -> poppler[version='>=0.67.0,<0.68.0a0'] -> glib[version='>=2.58.2,<2.59.0a0'] -> gettext[version='>=0.19.8.1,<1.0a0'] -> libffi[version='>=3.2.1,<3.3.0a0'] -> m2w64-gcc-libs
  - osmnx -> geopandas -> mapclassify -> scipy
  - osmnx -> geopandas -> pysal -> seaborn -> statsmodels[version='>=0.5.0'] -> patsy[version='>=0.4.0']

Current channels:

  - https://conda.anaconda.org/conda-forge/win-64
  - https://conda.anaconda.org/conda-forge/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

What can I do to get this working? Can anyone expand further on created github issues documentation? Or is this a different problem?

Code from Demo and Traceback of error:

import networkx as nx
import osmnx as ox
import requests
import matplotlib.cm as cm
import matplotlib.colors as colors
ox.config(use_cache=True, log_console=True)
ox.__version__

G = ox.graph_from_place('Piedmont, California, USA', network_type='drive')
fig, ax = ox.plot_graph(G)

Traceback from error

Traceback (most recent call last):
  File "C:\Users\pablo\Documents\2019 Spring\Discreet Math\Project\new Dijstra.py", line 9, in <module>
    G = ox.graph_from_place('Piedmont, California, USA', network_type='drive')
  File "C:\ProgramData\Anaconda3\lib\site-packages\osmnx\core.py", line 1879, in graph_from_place
    custom_filter=custom_filter)
  File "C:\ProgramData\Anaconda3\lib\site-packages\osmnx\core.py", line 1743, in graph_from_polygon
    polygon_utm, crs_utm = project_geometry(geometry=polygon)
  File "C:\ProgramData\Anaconda3\lib\site-packages\osmnx\projection.py", line 53, in project_geometry
    gdf_proj = project_gdf(gdf, to_crs=to_crs, to_latlong=to_latlong)
  File "C:\ProgramData\Anaconda3\lib\site-packages\osmnx\projection.py", line 119, in project_gdf
    projected_gdf = gdf.to_crs(utm_crs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\geopandas\geodataframe.py", line 443, in to_crs
    geom = df.geometry.to_crs(crs=crs, epsg=epsg)
  File "C:\ProgramData\Anaconda3\lib\site-packages\geopandas\geoseries.py", line 304, in to_crs
    proj_in = pyproj.Proj(self.crs, preserve_units=True)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyproj\__init__.py", line 362, in __new__
    return _proj.Proj.__new__(self, projstring)
  File "_proj.pyx", line 129, in _proj.Proj.__cinit__
RuntimeError: b'no arguments in initialization list'

Upvotes: 0

Views: 889

Answers (2)

Matt Najarian
Matt Najarian

Reputation: 181

It seems that you have already installed osmnx, otherwise you would receive the error:

ModuleNotFoundError: No module named osmnx

I had the same error and the solution offered by Jacopo worked for me. Just set the PROJ_LIB environment variable.

Upvotes: 0

Jacopo Repossi
Jacopo Repossi

Reputation: 365

You are facing different errors:

  1. Osmnx installation
  2. PyProj runtime error

Osmnx

It's not clear the steps you took in order to install osmnx (first you installed it, then you added conda-forge but it should have been the other way around), but as you can see your current channels win-64 and noarch don't have geopandas dependencies, so I guess you should run again conda config --add channels conda-forge and then reinstall osmnx (you no longer need --override-channels since by adding conda-forge you made it higher in priority)

PyProj Your RuntimeError: b'no arguments in initialization list' can be handle by setting the environment variable PROJ_LIB to match the path on your own machine, as you saw in the link you provided. It means you should provide the exact path of \Library\share that is linked to your virtual environment when your project actually is. Imagine you are working in "project_osmnx", then you should set

import os
os.environ["PROJ_LIB"] = "C:\Anaconda\envs\project_osmnx\Library\share"

If you are not familiar with conda environment or you don't know how to create one, check this link

Upvotes: 1

Related Questions