1

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)

I have also tried downloading using conda, which seems to have work for some people as well:

# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} pandana

Unfortunately this didn't solve the error for me.

Hope anyone can shed some light?

Thanks so much for your help!

Graciela Carrillo
  • 894
  • 11
  • 17
  • 1
    https://github.com/cython/cython/issues/1953#issuecomment-398128940 – ead Oct 07 '19 at 19:48
  • 2
    I'm never really sure how to help with this kind of question: (with Python 3.7 on Linux) I can compile and import Pandana so it clearly isn't _completely_ broken; we think the issue is probably where files have been compiled with an outdated version of Cython and it should be now fixed (but it could always be an ongoing bug that's hard to diagnose); this error message is clearly frustrating a number of people, but I don't have much idea how you'd actually diagnose it. – DavidW Oct 08 '19 at 07:30
  • I wonder if the best thing you could do would be to setup a new Conda environment with only the bare minimum packages needed for Pandana, and record exactly what those packages are and what commands you ran to install them. Then someone could at least try to build the exact same environment – DavidW Oct 08 '19 at 07:33

1 Answers1

2

Thanks @DavidW. 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 @ead's link to this github-issue 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.

ead
  • 32,758
  • 6
  • 90
  • 153
Graciela Carrillo
  • 894
  • 11
  • 17