0

我正在尝试使用 nx.read_gpickle 将 networkx 图形对象作为泡菜导入,并且收到 pyproj.crs 包不存在的错误。注意我正在使用GOSTnets,这是一个使用 networkx、geopandas、osmnx 和 peartree 为网络分析而开发的软件包。

我首先构建了图形,然后使用 osmnx.project_graph 进行投影并使用 GOSTnets.save 保存:

G_proj = ox.project_graph(G)

# save Graph as pickle using GOSTnets.save:
gn.save(G_proj,'processed_graph_cleaned_part1_proj','./', pickle = True, edges = False, nodes = False)

# save in networkx terms:
wpath = r"MYPATH"
savename = 'processed_graph_cleaned_part1_proj'
nx.write_gpickle(G, os.path.join(wpath, '%s.pickle' % savename))

然后在另一个笔记本中,我尝试导入图表:

import os, sys, time, importlib

import geopandas as gpd
import pandas as pd
import networkx as nx
import numpy as np
import GOSTnets as gn

# make sure osmium is installed (pip install osmium)
# An internal function called when creating the OSM_to_Network object will import osmium
from shapely.geometry import LineString, Point
import osmnx as ox

# import Graph pickle
G = nx.read_gpickle(r"MYPATH\processed_graph_cleaned_part1_proj.pickle")

这样做时,我收到以下错误:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-19-2be4f8fabb58> in <module>
      1 # read graph
      2 # this graph is the
----> 3 G = nx.read_gpickle(r"MYPATH\processed_graph_cleaned_proj.pickle")

<decorator-gen-748> in read_gpickle(path)

C:\WBG\Anaconda\envs\test_gostNets\lib\site-packages\networkx\utils\decorators.py in _open_file(func_to_be_decorated, *args, **kwargs)
    238         # Finally, we call the original function, making sure to close the fobj
    239         try:
--> 240             result = func_to_be_decorated(*new_args, **kwargs)
    241         finally:
    242             if close_fobj:

C:\WBG\Anaconda\envs\test_gostNets\lib\site-packages\networkx\readwrite\gpickle.py in read_gpickle(path)
     99     .. [1] https://docs.python.org/2/library/pickle.html
    100     """
--> 101     return pickle.load(path)
    102 
    103 

ModuleNotFoundError: No module named 'pyproj.crs.crs'; 'pyproj.crs' is not a package

我有 pyproj 版本:2.4.2.post1,构建:py36hc1560cf_1。Networkx 版本:2.4。在 jupyter 中使用 conda 运行。有谁知道发生了什么?抱歉,如果有重复的问题。

4

1 回答 1

0

您使用的是过时版本的 pyproj。例如,当前版本的 OSMnx需要pyproj>=2.6。2.4 版没有您尝试使用的 CRS 模块。确保根据其安装说明安装 OSMnx 。

这类似于此处回答的问题:Cannot import name 'CRS' from 'pyproj' for using the osmnx library

于 2020-07-31T18:14:01.567 回答