Search code examples
python-3.xnetworkxosmnxpyproj

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


I am trying to import a networkx graph object as a pickle using nx.read_gpickle, and am getting an error that pyproj.crs package does not exist. Heads up that I am using GOSTnets, a package developed for network analysis using networkx, geopandas, osmnx, and peartree.

I first constructed the graph, and then projected using osmnx.project_graph and saved using 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))

then in another notebook, I try to import the graph:

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")

When doing so, I receive the following error:

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

I have pyproj version: 2.4.2.post1, build: py36hc1560cf_1. Networkx version: 2.4. Running with conda in jupyter. Does anyone have an idea of what is happening? Apologies if a duplicate question.


Solution

  • You are using an outdated version of pyproj. For example, the current release of OSMnx requires pyproj>=2.6. Version 2.4 does not have the CRS module you are trying to use. Make sure you install OSMnx according to its installation instructions.

    This is similar to the question answered here: Cannot import name 'CRS' from 'pyproj' for using the osmnx library