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

徘徊边缘 提交于 2020-08-15 10:39:21

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/58275685/attributeerror-type-object-pandana-cyaccess-cyaccess-has-no-attribute-redu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!