I cannot install the rasterio package in a python repl

Question:
Hello,

I cant install the rasterio python package in my repl.

this is the error message I get:

Traceback (most recent call last):
File “main.py”, line 1, in
import rasterio
File “/home/runner/rasteriotest/venv/lib/python3.10/site-packages/rasterio/init.py”, line 28, in
from rasterio._version import gdal_version, get_geos_version, get_proj_version
ImportError: libexpat.so.1: cannot open shared object file: No such file or directory

This is what ghostwriter suggest, but I have not access to sudo:

The error is an import error caused by a missing dependency for rasterio library on line 1 of main.py. It seems that the system is missing the ‘libexpat’ shared library. To fix this, you will need to install ‘libexpat’ shared library.

On Ubuntu or Debian, you can install the library by running the following command:

sudo apt-get install -y libexpat-dev

On CentOS or RedHat, you can install the library by running the following command:

sudo yum install expat-devel

Once you have installed the ‘libexpat’ shared library, try running the code again.

This is the link to my reply: https://replit.com/@21satspleb/rasteriotest

Replit Profile: https://replit.com/@21satspleb

Try poetry add rasterio in the shell. This adds rasterio to poetry’s list of dependencies your Repl requires and installs it from PyPI.

1 Like

Hi Matt,

thanks for trying to help me!


Unfortunatly rasterio was already part of my pyproject.toml

Any other idea? To me it look like this libexpat.so.1 is missing on an environment level.

1 Like

It’s possible it thinks rasterio is installed when it isn’t; you could try poetry remove rasterio and pip uninstall rasterio to be safe, then re add it poetry add rasterio.

I followed your instruction, but still got the ImportError:

1 Like

Looked into rasterio, it requires GDAL to be installed. You can add this to the replit.nix file. Your replit.nix file should look something like this:

{ pkgs }: {
  deps = [
    pkgs.python310Full
    pkgs.replitPackages.prybar-python310
    pkgs.replitPackages.stderred
  ];
  env = {
    PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      # Needed for pandas / numpy
      pkgs.stdenv.cc.cc.lib
      pkgs.zlib
      # Needed for pygame
      pkgs.glib
      # Needed for matplotlib
      pkgs.xorg.libX11
      # Needed for rasterio
      pkgs.gdal
    ];
    PYTHONHOME = "${pkgs.python310Full}";
    PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
    LANG = "en_US.UTF-8";
    STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
    PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
  };
}
1 Like

Same error unfortunately … I also started with a new python repl:

  1. Added gdal to replit.nix
  2. poetry add rasterio
  3. checked if rasterio is installed with pip list
  4. Run → Error

Try this:

{ pkgs }: {
  deps = [
    pkgs.python310Full
    pkgs.replitPackages.prybar-python310
    pkgs.replitPackages.stderred
    # Needed for rasterio
    pkgs.gdal
  ];
  env = {
    PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      # Needed for pandas / numpy
      pkgs.stdenv.cc.cc.lib
      pkgs.zlib
      # Needed for pygame
      pkgs.glib
      # Needed for matplotlib
      pkgs.xorg.libX11
    ];
    PYTHONHOME = "${pkgs.python310Full}";
    PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
    LANG = "en_US.UTF-8";
    STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
    PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
  };
}

I have previously added ffmpeg in the same way.

1 Like

No luck, still the same error :confused:

I solved the problem, here are the steps:

Installation

  1. Add gdal to your replit.nix as pkgs.gdal under deps = like this:
> { pkgs }: {
>   deps = [
>     pkgs.python310Full
>     pkgs.replitPackages.prybar-python310
>     pkgs.replitPackages.stderred
>     pkgs.gdal
>     pkgs.exiftool
>   ];
>   env = {
>     PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
>       # Needed for pandas / numpy
>       pkgs.stdenv.cc.cc.lib
>       pkgs.zlib
>       # Needed for pygame
>       pkgs.glib
>       # Needed for matplotlib
>       pkgs.xorg.libX11
>     ];
>     PYTHONHOME = "${pkgs.python310Full}";
>     PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
>     LANG = "en_US.UTF-8";
>     STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
>     PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
>   };
> }
  1. Install python GDAL bindings from shell with pip install pygdal==“gdal-config --version.*”
    GitHub - nextgis/pygdal: Virtualenv and setuptools friendly version of standard GDAL python bindings

Here is a demo repl: https://replit.com/@21satspleb/gdaltest?v=1

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.