pysal / tobler

Spatial interpolation, Dasymetric Mapping, & Change of Support
https://pysal.org/tobler
BSD 3-Clause "New" or "Revised" License
144 stars 30 forks source link

Troubles importing tobler to a jupyter notebook #199

Closed brink395 closed 4 months ago

brink395 commented 5 months ago

Hi I am trying to install tobler with either conda or pip as described on the website:

conda install -c conda-forge tobler

and

pip install tobler

the installation seems to work smoothly, then when I try to import the package I get an error: " cannot import name 'asscalar' from 'numpy'"

I am using python version 3.11.5 and numpy 1.26.0

Thank you, -Gabriella

knaaptime commented 5 months ago

Can you post the full traceback? Sounds like you might be on an older version of numpy than you think. Can you also send the output from conda list?

brink395 commented 5 months ago

yes -

ImportError Traceback (most recent call last) Cell In[1], line 13 11 from google.oauth2 import service_account 12 import numpy as np ---> 13 import tobler

File ~\AnacondaDownload\envs\geospatpy\lib\site-packages\tobler__init__.py:9 6 import contextlib 7 from importlib.metadata import PackageNotFoundError, version ----> 9 from . import area_weighted, dasymetric, model, pycno, util 11 with contextlib.suppress(PackageNotFoundError): 12 version = version("tobler")

File ~\AnacondaDownload\envs\geospatpy\lib\site-packages\tobler\dasymetric__init__.py:1 ----> 1 from .masked_area_interpolate import masked_area_interpolate 2 from .raster_tools import extract_raster_features, _fast_append_profile_in_gdf

File ~\AnacondaDownload\envs\geospatpy\lib\site-packages\tobler\dasymetric\masked_area_interpolate.py:4 1 import geopandas as gpd 3 from ..area_weighted import area_interpolate ----> 4 from .raster_tools import extract_raster_features 5 from warnings import warn 8 def masked_area_interpolate( 9 source_df, 10 target_df, (...) 19 codes=None, 20 ):

File ~\AnacondaDownload\envs\geospatpy\lib\site-packages\tobler\dasymetric\raster_tools.py:16 14 import warnings 15 from ..util.util import _check_presence_of_crs ---> 16 import rasterstats as rs 19 def _chunk_dfs(geoms_to_chunk, n_jobs): 20 chunk_size = geoms_to_chunk.shape[0] // n_jobs + 1

File ~\AnacondaDownload\envs\geospatpy\lib\site-packages\rasterstats__init.py:3 1 # -- coding: utf-8 -- 2 from .main import gen_zonal_stats, raster_stats, zonal_stats ----> 3 from .point import gen_point_query, point_query 4 from rasterstats import cli 5 from rasterstats._version import version__

File ~\AnacondaDownload\envs\geospatpy\lib\site-packages\rasterstats\point.py:6 4 from shapely import wkt 5 from numpy.ma import masked ----> 6 from numpy import asscalar 7 from .io import read_features, Raster 10 def point_window_unitxy(x, y, affine):

ImportError: cannot import name 'asscalar' from 'numpy'

conda list

access 1.1.9 pypi_0 pypi affine 2.3.0 pyhd3eb1b0_0
aiofiles 22.1.0 py39haa95532_0
aiohttp 3.9.0 pypi_0 pypi aiosignal 1.3.1 pypi_0 pypi aiosqlite 0.18.0 py39haa95532_0
anyio 3.5.0 py39haa95532_0
argon2-cffi 21.3.0 pyhd3eb1b0_0
argon2-cffi-bindings 21.2.0 py39h2bbff1b_0
asttokens 2.0.5 pyhd3eb1b0_0
async-timeout 4.0.3 pypi_0 pypi atpublic 4.0 pypi_0 pypi attrs 23.1.0 py39haa95532_0
babel 2.11.0 py39haa95532_0
backcall 0.2.0 pyhd3eb1b0_0
beautifulsoup4 4.12.2 py39haa95532_0
bidict 0.22.1 pypi_0 pypi bigframes 0.14.1 pypi_0 pypi blas 1.0 mkl
bleach 4.1.0 pyhd3eb1b0_0
blosc 1.21.3 h6c2663c_0
boost-cpp 1.82.0 h59b6b97_2
bottleneck 1.3.5 py39h080aedc_0
branca 0.6.0 py39haa95532_0
brotli 1.0.9 h2bbff1b_7
brotli-bin 1.0.9 h2bbff1b_7
brotli-python 1.0.9 py39hd77b12b_7
bs4 4.12.2 py38hd3eb1b0_0
bzip2 1.0.8 he774522_0
ca-certificates 2024.2.2 h56e8100_0 conda-forge
cachetools 5.3.2 pypi_0 pypi cairo 1.16.0 haedb8bc_5
cartopy 0.18.0 py39h80a4efb_1
certifi 2023.11.17 pyhd8ed1ab_0 conda-forge
cffi 1.15.1 py39h2bbff1b_3
cfitsio 3.470 h2bbff1b_7 charset-normalizer 2.0.4 pyhd3eb1b0_0 click 8.1.7 py39haa95532_0 click-plugins 1.1.1 pyhd3eb1b0_0 cligj 0.7.2 py39haa95532_0 cloudpickle 3.0.0 pypi_0 pypi colorama 0.4.6 py39haa95532_0 comm 0.2.0 pypi_0 pypi contourpy 1.0.5 py39h59b6b97_0 cryptography 41.0.3 py39h89fc84f_0 curl 8.1.1 h2bbff1b_0 cycler 0.11.0 pyhd3eb1b0_0 db-dtypes 1.1.1 pypi_0 pypi debugpy 1.6.7 py39hd77b12b_0 decorator 5.1.1 pyhd3eb1b0_0 defusedxml 0.7.1 pyhd3eb1b0_0 deprecated 1.2.14 pyh1a96a4e_0 conda-forge deprecation 2.1.0 pypi_0 pypi descartes 1.1.0 py_4 conda-forge entrypoints 0.4 py39haa95532_0 esda 2.5.1 pypi_0 pypi exceptiongroup 1.0.4 py39haa95532_0 executing 0.8.3 pyhd3eb1b0_0 expat 2.5.0 hd77b12b_0 filelock 3.13.1 pypi_0 pypi fiona 1.8.22 py39hac22706_0 folium 0.14.0 py39haa95532_0 fontconfig 2.14.1 h9c4af85_2 fonttools 4.25.0 pyhd3eb1b0_0 freetype 2.12.1 ha860e81_0 freexl 1.0.6 h2bbff1b_0 frozenlist 1.4.0 pypi_0 pypi fsspec 2023.10.0 pypi_0 pypi gcsfs 2023.10.0 pypi_0 pypi gdal 3.0.2 pypi_0 pypi geopandas 0.14.3 pypi_0 pypi geos 3.8.0 h33f27b4_0 geotiff 1.7.0 h4545760_1 giddy 2.3.5 pypi_0 pypi giflib 5.2.1 h8cc25b3_3 glib 2.69.1 h5dc1a3c_2 google-api-core 2.14.0 pypi_0 pypi google-auth 2.23.4 pypi_0 pypi google-auth-oauthlib 1.1.0 pypi_0 pypi google-cloud-bigquery 3.13.0 pypi_0 pypi google-cloud-bigquery-connection 1.13.2 pypi_0 pypi google-cloud-bigquery-storage 2.22.0 pypi_0 pypi google-cloud-core 2.3.3 pypi_0 pypi google-cloud-functions 1.13.3 pypi_0 pypi google-cloud-iam 2.12.2 pypi_0 pypi google-cloud-resource-manager 1.10.4 pypi_0 pypi google-cloud-storage 2.13.0 pypi_0 pypi google-crc32c 1.5.0 pypi_0 pypi google-resumable-media 2.6.0 pypi_0 pypi googleapis-common-protos 1.61.0 pypi_0 pypi greenlet 3.0.1 pypi_0 pypi grpc-google-iam-v1 0.12.7 pypi_0 pypi grpcio 1.59.3 pypi_0 pypi grpcio-status 1.59.3 pypi_0 pypi hdf4 4.2.13 h712560f_2 hdf5 1.10.6 h1756f20_1 humanize 4.9.0 pypi_0 pypi ibis-framework 6.2.0 pypi_0 pypi icc_rt 2022.1.0 h6049295_2 icu 73.1 h6c2663c_0 idna 3.4 py39haa95532_0 importlib-metadata 6.0.0 py39haa95532_0 importlib_metadata 6.0.0 hd3eb1b0_0 importlib_resources 6.1.0 py39haa95532_0 inequality 1.0.0 pypi_0 pypi intel-openmp 2023.1.0 h59b6b97_46319 ipykernel 6.25.0 py39h9909e9c_0 ipython 8.15.0 py39haa95532_0 ipython_genutils 0.2.0 pyhd3eb1b0_1 ipywidgets 8.1.1 pypi_0 pypi jedi 0.18.1 py39haa95532_1 jinja2 3.1.2 py39haa95532_0 joblib 1.2.0 py39haa95532_0 jpeg 9e h2bbff1b_1 json5 0.9.6 pyhd3eb1b0_0 jsonschema 4.19.2 py39haa95532_0 jsonschema-specifications 2023.7.1 py39haa95532_0 jupyter_client 7.4.9 py39haa95532_0 jupyter_core 5.5.0 py39haa95532_0 jupyter_events 0.8.0 py39haa95532_0 jupyter_server 1.23.4 py39haa95532_0 jupyter_server_fileid 0.9.0 py39haa95532_0 jupyter_server_ydoc 0.8.0 py39haa95532_1 jupyter_ydoc 0.2.4 py39haa95532_0 jupyterlab 3.6.3 py39haa95532_0 jupyterlab-widgets 3.0.9 pypi_0 pypi jupyterlab_pygments 0.1.2 py_0 jupyterlab_server 2.22.0 py39haa95532_0 kealib 1.4.14 hde4a422_1 kiwisolver 1.4.4 py39hd77b12b_0 krb5 1.20.1 h5b6d351_0 lcms2 2.12 h83e58a3_0 lerc 3.0 hd77b12b_0 libboost 1.82.0 h3399ecb_2 libbrotlicommon 1.0.9 h2bbff1b_7 libbrotlidec 1.0.9 h2bbff1b_7 libbrotlienc 1.0.9 h2bbff1b_7 libclang 14.0.6 default_hb5a9fac_1 libclang13 14.0.6 default_h8e68704_1 libcurl 8.1.1 h86230a5_0 libdeflate 1.17 h2bbff1b_1 libffi 3.4.4 hd77b12b_0 libgdal 3.0.2 hc12e7b7_6 libiconv 1.16 h2bbff1b_2 libkml 1.3.0 h63940dd_7 libnetcdf 4.8.1 h6685c40_2 libpng 1.6.39 h8cc25b3_0 libpq 12.15 h906ac69_0 libpysal 4.8.1 pypi_0 pypi libsodium 1.0.18 h62dcd97_0 libspatialindex 1.9.3 h6c2663c_0 libspatialite 4.3.0a h6ec8781_23 libssh2 1.10.0 he2ea4bf_2 libtiff 4.5.1 hd77b12b_0 libwebp 1.3.2 hbc33d0d_0 libwebp-base 1.3.2 h2bbff1b_0 libxml2 2.10.4 h0ad7f3c_1 libzip 1.8.0 h289538f_1 llvmlite 0.42.0 pypi_0 pypi lz4-c 1.9.4 h2bbff1b_0 m2w64-expat 2.1.1 2 m2w64-gcc-libgfortran 5.3.0 6 m2w64-gcc-libs 5.3.0 7 m2w64-gcc-libs-core 5.3.0 7 m2w64-gettext 0.19.7 2 m2w64-gmp 6.1.0 2 m2w64-libiconv 1.14 6 m2w64-libwinpthread-git 5.0.0.4634.697f757 2
m2w64-xz 5.2.2 2 mapclassify 2.5.0 py39haa95532_0 markdown-it-py 3.0.0 pypi_0 pypi markupsafe 2.1.1 py39h2bbff1b_0 matplotlib 3.8.0 py39hcbf5309_2 conda-forge matplotlib-base 3.8.0 py39h4ed8f06_0 matplotlib-inline 0.1.6 py39haa95532_0 mdurl 0.1.2 pypi_0 pypi mgwr 2.2.1 pypi_0 pypi mistune 2.0.4 py39haa95532_0 mkl 2023.1.0 h6b88ed4_46357 mkl-service 2.4.0 py39h2bbff1b_1 mkl_fft 1.3.8 py39h2bbff1b_0 mkl_random 1.2.4 py39h59b6b97_0 momepy 0.6.0 pypi_0 pypi mpmath 1.3.0 pypi_0 pypi msys2-conda-epoch 20160418 1 multidict 6.0.4 pypi_0 pypi multipledispatch 1.0.0 pypi_0 pypi munch 2.5.0 pyhd3eb1b0_0 munkres 1.1.4 py_0 nbclassic 0.5.5 py39haa95532_0 nbclient 0.8.0 py39haa95532_0 nbconvert 7.10.0 py39haa95532_0 nbformat 5.9.2 py39haa95532_0 nest-asyncio 1.5.6 py39haa95532_0 networkx 3.1 py39haa95532_0 notebook 6.5.4 py39haa95532_1 notebook-shim 0.2.3 py39haa95532_0 numba 0.59.0 pypi_0 pypi numexpr 2.8.7 py39h2cd9be0_0 numpy 1.26.0 py39h055cbcc_0 numpy-base 1.26.0 py39h65a83cf_0 oauthlib 3.2.2 pypi_0 pypi openjpeg 2.4.0 h4fc8c34_0 openssl 3.0.12 h2bbff1b_0 packaging 23.1 py39haa95532_0 palettable 3.3.3 pyhd8ed1ab_0 conda-forge pandas 2.1.1 py39h4ed8f06_0 pandocfilters 1.5.0 pyhd3eb1b0_0 parso 0.8.3 pyhd3eb1b0_0 parsy 2.1 pypi_0 pypi patsy 0.5.3 py39haa95532_0 pcre 8.45 hd77b12b_0 pcre2 10.42 h0ff8eda_0 pickleshare 0.7.5 pyhd3eb1b0_1003 pillow 10.0.1 py39h045eedc_0 pip 23.3 py39haa95532_0 pixman 0.40.0 h2bbff1b_1 platformdirs 3.10.0 py39haa95532_0 ply 3.11 py_1 conda-forge pointpats 2.4.0 pypi_0 pypi pooch 1.8.0 pypi_0 pypi poppler 22.12.0 h268424c_0 poppler-data 0.4.11 haa95532_1 proj 6.2.1 h3758d61_0 prometheus_client 0.14.1 py39haa95532_0 prompt-toolkit 3.0.36 py39haa95532_0 proto-plus 1.22.3 pypi_0 pypi protobuf 4.25.1 pypi_0 pypi psutil 5.9.0 py39h2bbff1b_0 pulp 2.8.0 pypi_0 pypi pure_eval 0.2.2 pyhd3eb1b0_0 pyarrow 14.0.1 pypi_0 pypi pyasn1 0.5.1 pypi_0 pypi pyasn1-modules 0.3.0 pypi_0 pypi pycparser 2.21 pyhd3eb1b0_0 pydata-google-auth 1.8.2 pypi_0 pypi pygments 2.15.1 py39haa95532_1 pyogrio 0.7.2 pypi_0 pypi pyopenssl 23.2.0 py39haa95532_0 pyparsing 3.0.9 py39haa95532_0 pyproj 3.6.1 pypi_0 pypi pyqt 5.15.10 py39hd77b12b_0 pyqt5-sip 12.13.0 py39h2bbff1b_0 pysal 24.1 pypi_0 pypi pyshp 2.1.3 pyhd3eb1b0_0 pysocks 1.7.1 py39haa95532_0 python 3.9.18 h1aa4202_0 python-dateutil 2.8.2 pyhd3eb1b0_0 python-fastjsonschema 2.16.2 py39haa95532_0 python-json-logger 2.0.7 py39haa95532_0 python-tzdata 2023.3 pyhd3eb1b0_0 python_abi 3.9 2_cp39 conda-forge pytz 2023.3.post1 py39haa95532_0 pywin32 305 py39h2bbff1b_0 pywinpty 2.0.10 py39h5da7b33_0 pyyaml 6.0.1 py39h2bbff1b_0 pyzmq 23.2.0 py39hd77b12b_0 qhull 2020.2 h59b6b97_2 qt-main 5.15.2 h19c9488_10 quantecon 0.7.1 pypi_0 pypi rasterio 1.2.10 py39h17c1fa0_0 rasterstats 0.14.0 py_0 referencing 0.30.2 py39haa95532_0 requests 2.31.0 py39haa95532_0 requests-oauthlib 1.3.1 pypi_0 pypi rfc3339-validator 0.1.4 py39haa95532_0 rfc3986-validator 0.1.1 py39haa95532_0 rich 13.7.0 pypi_0 pypi rpds-py 0.10.6 py39h062c2fa_0 rsa 4.9 pypi_0 pypi rtree 1.0.1 py39h2eaa2aa_0 scikit-learn 1.3.0 py39h4ed8f06_0 scipy 1.11.3 py39h309d312_0 seaborn 0.13.2 hd8ed1ab_0 conda-forge seaborn-base 0.13.2 pyhd8ed1ab_0 conda-forge segregation 2.5 pypi_0 pypi send2trash 1.8.2 py39haa95532_0 setuptools 68.0.0 py39haa95532_0 shapely 2.0.1 py39hd7f5953_0 simplejson 3.17.6 py39h2bbff1b_0 sip 6.7.12 py39hd77b12b_0 six 1.16.0 pyhd3eb1b0_1 sniffio 1.2.0 py39haa95532_1 snuggs 1.4.7 pyhd3eb1b0_0 soupsieve 2.5 py39haa95532_0 spaghetti 1.7.4 pypi_0 pypi spglm 1.1.0 pypi_0 pypi spint 1.0.7 pypi_0 pypi splot 1.1.5.post1 pypi_0 pypi spopt 0.5.0 pypi_0 pypi spreg 1.4.2 pypi_0 pypi spvcm 0.3.0 pypi_0 pypi sqlalchemy 2.0.23 pypi_0 pypi sqlglot 17.16.2 pypi_0 pypi sqlite 3.41.2 h2bbff1b_0 stack_data 0.2.0 pyhd3eb1b0_0 statsmodels 0.14.0 py39h9128911_0 sympy 1.12 pypi_0 pypi tbb 2021.8.0 h59b6b97_0 terminado 0.17.1 py39haa95532_0 threadpoolctl 2.2.0 pyh0d69192_0 tiledb 2.3.3 hd8964de_3 tinycss2 1.2.1 py39haa95532_0 tk 8.6.12 h2bbff1b_0 tobler 0.11.2 pypi_0 pypi tomli 2.0.1 py39haa95532_0 toolz 0.12.0 pypi_0 pypi tornado 6.3.3 py39h2bbff1b_0 tqdm 4.66.1 pypi_0 pypi traitlets 5.7.1 py39haa95532_0 typing-extensions 4.7.1 py39haa95532_0 typing_extensions 4.7.1 py39haa95532_0 tzdata 2023c h04d1e81_0 uriparser 0.9.7 h2bbff1b_0 urllib3 1.26.18 py39haa95532_0 vc 14.2 h21ff451_1 vs2015_runtime 14.27.29016 h5e58377_2 wcwidth 0.2.5 pyhd3eb1b0_0 webencodings 0.5.1 py39haa95532_1 websocket-client 0.58.0 py39haa95532_4 wheel 0.41.2 py39haa95532_0 widgetsnbextension 4.0.9 pypi_0 pypi win_inet_pton 1.1.0 py39haa95532_0 winpty 0.4.3 4 wrapt 1.14.1 py39hb82d6ee_0 conda-forge xerces-c 3.2.4 hd77b12b_1 xxhash 3.4.1 pypi_0 pypi xyzservices 2022.9.0 py39haa95532_1 xz 5.4.2 h8cc25b3_0 y-py 0.5.9 py39hb6bf4ef_0 yaml 0.2.5 he774522_0 yarl 1.9.3 pypi_0 pypi ypy-websocket 0.8.2 py39haa95532_0 zeromq 4.3.4 hd77b12b_0 zipp 3.11.0 py39haa95532_0 zlib 1.2.13 h8cc25b3_0 zstd 1.5.5 hd43e919_0

knaaptime commented 5 months ago

weird, im not sure. You can see the error is coming from rasterstats trying to use asscalar which was removed in numpy 1.23 (but like you said, you've got 1.26 there in your environment). Maybe try doing

import numpy
numpy.__version__

and make sure its actually 1.26 in case your kernel isnt aligned with your environment or something?

knaaptime commented 5 months ago

although your environment has a ton of pip packages in it, which is a recipe for disaster. Try rebuilding your environment using conda only. My guess is you're ending up with a different numpy under the hood because of one of those pip-installed packages (and tobler itself should definitely be installed from conda, not pip)

edit: it looks like these packages are from pip, the general conda channel, and the conda-forge channel, which will get things all out of wack. Try building your environment using only the conda-forge channel. That is guaranteed to get you up and running

brink395 commented 5 months ago

Ok, thank you. I will try building a new environment.