0

I am trying to import the package rasterio into python and jupyter notebook, link to package: https://rasterio.readthedocs.io/en/latest/installation.html

Just to start off clean, I created a virtual environment, I will call projectenv

I access projectenv in my terminal via: projectenv\Scripts\activate

I then download all of the necessary dependencies for rasterio from this suggested website hosting the needed binary wheel files: https://www.lfd.uci.edu/~gohlke/pythonlibs/

I specifically install these packages/wheel files via pip: GDAL-3.4.2-cp39-cp39-win_amd64.whl, Fiona-1.8.21-cp39-cp39-win_amd64.whl, Shapely-1.8.1.post1-cp39-cp39-win_amd64.whl, pyproj-3.3.0-cp39-cp39-win_amd64.whl, Rtree-1.0.0-cp39-cp39-win_amd64.whl

(Though I am not sure about Rtree being needed).

Everything installs fine. And to test I simply access python in my terminal from projectenv and trying importing rasterio via simply import rasterio, and it is successfully imported. However, this is just in my terminal window, and I want to import rasterio into a jupyter notebook.

And so I run ipython kernel install --user --name=projectenv to get a kernel for this virtual environment running in jupyter notebook. In my terminal, within projectenv, I simply run jupyter notebook to open jupyter notebook and then I open a new notebook in "projectenv". Now in the new jupyter notebook, I go to Kernel > Change kernel and select projectenv and the kernel is then ready. I then simply run import rasterio and I see this error message (full traceback included):

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13964/1380003273.py in <module>
----> 1 import rasterio

~\AppData\Roaming\Python\Python39\site-packages\rasterio\__init__.py in <module>
     15 from pathlib import Path
     16 
---> 17 from rasterio._base import gdal_version
     18 from rasterio.drivers import driver_from_extension, is_blacklisted
     19 from rasterio.dtypes import (

ImportError: DLL load failed while importing _base: The specified module could not be found.

How come this is happening if I was previously able to import rasterio in my terminal? I am trying to find a way to fix this, but it seems like rasterio was installed fine, but just cannot be imported into jupyter notebook for some reason. I am thinking perhaps I am not properly changing the kernel correctly in jupyter notebook.

  • `AppData\Roaming\Python\Python39\site-packages\rasterio` doesn't look like it's loaded from a virtual environment. – cgohlke May 11 '22 at 03:25

0 Answers0