You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

使用rasterio.mask.mask()时出现AttributeError: module 'rasterio' has no attribute 'mask'的问题排查

Troubleshooting AttributeError: module 'rasterio' has no attribute 'mask' in Rasterio

Hey there! Let's break down why you're hitting this error and get your code back on track. That error pops up when your Rasterio setup can't locate the mask module—even though the docs confirm it exists—here are the most common fixes to try:

1. You're running an outdated Rasterio version

The rasterio.mask module was officially added in Rasterio 1.0.0. If you're using a version older than that, this module simply won't be available.

First, check your current Rasterio version with this quick snippet:

import rasterio as rio
print(rio.__version__)

If the version is below 1.0.0, upgrade to the latest stable release:

  • For pip users:
    pip install --upgrade rasterio
    
  • For conda users:
    conda update rasterio
    

2. There's a file name conflict in your working directory

If you have a file named rasterio.py (or rasterio.pyc) in the same folder where you're running your script, it will override the official Rasterio library. Your code will try to import this local file instead of the real module, which doesn't include the mask functionality.

Check your current directory for any such files, rename or delete them, then restart your Python kernel/terminal and re-run your code.

3. Your Rasterio installation is corrupted

Occasionally, installations can get messed up, leading to missing or broken modules. If upgrading didn't fix the issue, try a clean reinstall:

  • Pip:
    pip uninstall rasterio -y
    pip install rasterio
    
  • Conda:
    conda remove rasterio -y
    conda install rasterio
    

Once you resolve the root cause, your line out_image, out_transform = rio.mask.mask(src, nReserve_proj.geometry,crop=True) should work exactly as the official documentation describes.

内容的提问来源于stack exchange,提问作者mir abir hossain

火山引擎 最新活动