0

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

研究我遇到的问题OSMnx graph_from_place #251,我不太确定如何“自定义环境以匹配我自己机器上的路径”,如问题页面底部所述,但它提供了安装链接OSMnx 在虚拟环境中。从那里我厌倦了卸载 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 问题文档吗?或者这是一个不同的问题?

来自 Demo 的代码和错误的追溯:

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

2 回答 2

1

您面临不同的错误:

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

Osmnx

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

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

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

如果您不熟悉 conda 环境或不知道如何创建,请查看此链接

于 2019-04-23T08:08:33.023 回答
0

看来你已经安装了osmnx,否则你会收到错误:

ModuleNotFoundError:没有名为 osmnx 的模块

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

于 2019-05-06T18:39:26.153 回答