Osmnx ox.graph_from_place RuntimeError:b'初始化列表中没有参数'

时间:2019-04-18 05:02:58

标签: python-3.x anaconda osmnx

我尝试运行demo,但是无论尝试什么,当我尝试使用RuntimeError: b'no arguments in initialization list'时都会得到ox.graph_from_place。我已经搜索了多个地方,但没有找到任何答案。我使用的是Windows 10,python 3.7,我的OSMNX版本是0.9。

正在研究我遇到的问题OSMnx graph_from_place #251,但我不确定如何按照问题页面底部的说明如何“自定义环境以匹配我自己计算机上的路径”,但这给了link to installing OSMnx in a virtual environment。从那里,我厌倦了卸载osmnx和conda install -c conda-forge osmnx(工作正常)以及conda config --add channels conda-forge,也尝试了conda create --override-channels -c conda-forge -n OSMNX python=3 osmnx,但这给了我

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.

我该怎么做才能使它正常工作?任何人都可以进一步扩展已创建的github问题文档吗?还是这是一个不同的问题?

演示和错误回溯代码:

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 (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'

2 个答案:

答案 0 :(得分:1)

您面临着不同的错误:

  1. Osmnx安装
  2. PyProj运行时错误

Osmnx

目前尚不清楚您安装osmnx所采取的步骤(首先安装了它,然后添加了conda-forge,但应该是相反的方式),但是您可以看到当前的频道win-64和noarch没有geopandas依赖性,因此我想您应该再次运行conda config --add channels conda-forge,然后重新安装osmnx(您不再需要--override-channels了,因为通过添加conda-forge优先级更高)

PyProj 您可以通过设置环境变量PROJ_LIB来匹配您自己的计算机上的路径来处理RuntimeError: b'no arguments in initialization list',如您在提供的链接中所看到的。 这意味着您应该在项目实际存在时提供链接到虚拟环境的\ Library \ share的确切路径。 假设您正在“ project_osmnx”中工作,那么应该设置

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

如果您不熟悉conda环境或不知道如何创建环境,请选中此link

答案 1 :(得分:0)

似乎您已经安装了osmnx,否则您将收到错误消息:

  

ModuleNotFoundError:没有名为osmnx的模块

我遇到了同样的错误,Jacopo提供的解决方案为我工作。只需设置PROJ_LIB环境变量。