You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用pyrosm获取驾驶路网触发TypeError,求错误原因排查

问题原因与修复方案

核心原因

报错TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'是因为pyrosm在解析OSM道路数据时,遇到了某个需要转换为整数的字段存在空值(None),无法完成类型转换。

可能的触发场景及修复步骤

  1. OSM本地数据损坏/不完整

    • 删除/home/brunob/mapas目录下的sudeste相关文件,重新运行代码下载完整数据,避免因断点下载导致的数据缺失。
  2. pyrosm版本与Python3.11不兼容

    • 升级pyrosm到最新稳定版:
      pip install --upgrade pyrosm
      
    • 若升级后问题仍存在,尝试降级到适配Python3.11的版本(如0.7.0):
      pip install pyrosm==0.7.0
      
  3. 数据中存在异常道路要素

    • 绕过内置的driving过滤规则,先获取全量路网再手动筛选:
      from pyrosm import OSM, get_data
      import osmnx as ox
      import time
      
      osm = OSM(get_data("sudeste", directory="/home/brunob/mapas"))
      
      # 获取全量路网
      all_net = osm.get_network(network_type="all")
      # 手动筛选符合驾驶通行的道路类型
      valid_driving_highways = [
          "motorway", "trunk", "primary", "secondary", "tertiary",
          "unclassified", "residential", "service"
      ]
      drive_net = all_net[all_net["highway"].isin(valid_driving_highways)]
      drive_net.plot()
      

内容的提问来源于stack exchange,提问作者user908109

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 20:13:21