1

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.

jblng
  • 13
  • 1
  • 4
  • Welcome to Stack Overflow. Did you already follow the [tour]? Please also read [how to ask a question](https://stackoverflow.com/help/how-to-ask), since you didn't include a [mre]. Adding it would be very helpful. – wovano Jul 31 '20 at 16:01
  • hi @wovano, thank you for the heads up. I added a code example and more details. – jblng Jul 31 '20 at 17:03
  • @jbelanger thanks for adding more code. Can you extend the code how you create the save file? Then we can reproduce your error and propose solutions. From the current information, I would guess you need to import [pyproj (?)](https://pyproj4.github.io/pyproj/dev/api/crs/crs.html) in your notebook where you load the savefile. – Sparky05 Jul 31 '20 at 17:17
  • hi @Sparky05, thanks for your response. The error persists after importing pyproj. Please note in edited post that I am using a python wrapper for networkx/osmnx/geopands/peartree called GOSTnets. however the issue seems to be related to the osmnx projected graph. All other non-projected graphs import fine in the same conda environment. – jblng Jul 31 '20 at 17:30

1 Answers1

0

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

gboeing
  • 5,691
  • 2
  • 15
  • 41
  • thanks very much for the helpful answer. Per the installation instructions - do i have to create a new ox environment, or can i update an existing one instead? i saw from related question you shared that i can't simply `conda/pip install osmnx/pyproj`. – jblng Jul 31 '20 at 19:02
  • 1
    I'd recommend you create a new environment to keep it nice and clean. Install all the packages you want in it in the single line when you create it. – gboeing Jul 31 '20 at 19:19
  • NB, this also seems in line with [this answer](https://stackoverflow.com/a/61797506/10669875) on a similar/related question. – wovano Jul 31 '20 at 20:51
  • thanks very much @gboeing & @wovano! the new env with updated osmnx solved the problem :) – jblng Aug 03 '20 at 15:26