UDST / pandana

Pandas Network Analysis by UrbanSim: fast accessibility metrics and shortest paths, using contraction hierarchies :world_map:
http://udst.github.io/pandana
GNU Affero General Public License v3.0
386 stars 84 forks source link

AttributeError: type object 'pandana.cyaccess.cyaccess' has no attribute '__reduce_cython__' #126

Closed gracecarrillo closed 4 years ago

gracecarrillo commented 4 years ago

Hi,

I've installed pandana from git:

!{sys.executable} -m pip install git+git://github.com/udst/pandana.git

on my jupyterlab:

/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from fiona->geopandas>=0.2.1->osmnet>=0.1.2->pandana) (7.0)

I'm running this code :

import pandana, time, os, pandas as pd, numpy as np
from pandana.loaders import osm

# define your selected amenities and bounding box
# configure search at a max distance of 1 km for up to the 10 nearest points-of-interest
amenities = ['restaurant', 'bar', 'food']
distance = 1000
num_pois = 10
num_categories = len(amenities) + 1 #one for each amenity, plus one extra for all of them combined

# bounding box as a list of llcrnrlat, llcrnrlng, urcrnrlat, urcrnrlng
# Bounding box for a Edinburgh, Scotland
west, south, east, north = (-3.449533, 55.818792, -3.074951, 56.004084)
bbox = [west, south, east, north] #lat-long bounding box for Edinburgh, Scotland

I'm following this Geoff Boeing's tutorial: andana-accessibility-demo-full.ipynb

When I run the code I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-183-27bb5991aaa3> in <module>
----> 1 import pandana, time, os, pandas as pd, numpy as np
      2 from pandana.loaders import osm
      3 
      4 # define your selected amenities and bounding box
      5 # configure search at a max distance of 1 km for up to the 10 nearest points-of-interest

~/conda/envs/python/lib/python3.6/site-packages/pandana/__init__.py in <module>
----> 1 from .network import Network
      2 
      3 version = __version__ = '0.4.4'

~/conda/envs/python/lib/python3.6/site-packages/pandana/network.py in <module>
      9 from sklearn.neighbors import KDTree
     10 
---> 11 from .cyaccess import cyaccess
     12 from .loaders import pandash5 as ph5
     13 import warnings

src/cyaccess.pyx in init pandana.cyaccess()

AttributeError: type object 'pandana.cyaccess.cyaccess' has no attribute '__reduce_cython__'

The reduce_cython error appears a few times when I search in Google but I haven't been able to find something that solves my issue. So far, I've tried updating cython and numpy, which appears to have worked for other people when facing a related issue:

!{sys.executable} -m pip install --upgrade cython
# Output: Requirement already up-to-date: cython in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (0.29.13)

!{sys.executable} -m pip install --upgrade numpy
# Output: Requirement already up-to-date: numpy in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (1.17.2)

Unfortunately this didn't solve the error for me.

Hope anyone can shed some light?

Thanks so much for your help!

gracecarrillo commented 4 years ago

UPDATE. Here's what I did and it fixed the problem:

First, since I am using Collaboratory, I just re-started my session for pandana to uninstall.

I then upgraded Cython:

import sys
!{sys.executable} -m pip install --upgrade cython

# Output: 
Collecting cython
  Downloading https://files.pythonhosted.org/packages/45/f2/a7101b3457561e57f5abcd6f5ac13190054fecd7370f58f36fe2d6574742/Cython-0.29.13-cp36-cp36m-manylinux1_x86_64.whl (2.1MB)
     |████████████████████████████████| 2.1MB 1.9MB/s eta 0:00:01
Installing collected packages: cython
Successfully installed cython-0.29.13 

Only then, I installed pandana:

!{sys.executable} -m pip install pandana

And is now working just fine.

So it seems this post (github.com/cython/cython/issues/1953#issuecomment-398128940) makes sense. The cython implemented package was built with the incorrect Cython version to begin with. Had to uninstall, then upgrade Cython and only then, install pandana.

smmaurer commented 4 years ago

Hi @gracecarrillo,

Thanks for posting the solution for this! We haven't done any testing with installation in JupyterLab before, but it seems like we should.

It's possible that requiring a specific version of Cython in the Pandana setup code would help with this -- i'll look into it.

Sam