0

I've been trying to create a layer for Lambda that would allow me to use shapely for runtime python 3.9. For some reason lambda just keeps returning the error: lambda_function': No module named 'shapely.lib

So there's probably something wrong with my .zip file. Ive installed in path shapely.zip/python/..

Here's what Ive done so far:

  1. Looked for dependencies and ended up zipping up together in a python3 venv: shapely, geos, pyproj and numpy like this:

    mkdir python
    python3 -m venv env
    source env/bin/activate
    cd python
    pip3 install shapely -t python
    pip3 install geos -t python
    pip3 install numpy -t python
    pip3 install pyproj -t python
    zip -r shapely.zip python

I also tried pip install shapely, but that returned Nothing to do.

  1. Tried altinstalling python 3.9 on an ec2 (with amazon linux 2) and running it in virtual environment, but the ec2 keeps telling me that python3.9 is an unknown command. Ive had to fight with layers before but this seems to be the most notorious so far.

  2. I also noticed that by running "pip3 install geos", I it probably installed a wrong version, so I tried to install a tar.bz2 for geos 3.9 and install it like with what I found from the internet:

    wget http://download.osgeo.org/geos/geos-3.9.0.tar.bz2
    tar xvfj geos-3.9.0.tar.bz2
    cd geos-3.9.0
    ./configure
    make
    sudo make install

But that gave me this weird error:

`/bin/mkdir -p '/usr/local/lib'
 '/bin/sh ../libtool   --mode=install /bin/install -c   libgeos.la 
'/usr/local/lib'`    
`libtool: install: 'libgeos.la' is not a valid libtool archive'`  
`libtool: install: Try 'libtool --help --mode=install' for more 
information.`  
`make[4]: *** [install-libLTLIBRARIES] Error 1`  
`make[4]: Leaving directory '/usr/python/python/geos-3.9.0/src'`  
`make[3]: *** [install-am] Error 2`  
`make[3]: Leaving directory '/usr/python/python/geos-3.9.0/src'`  
`make[2]: *** [install-recursive] Error 1`  
`make[2]: Leaving directory '/usr/python/python/geos-3.9.0/src'`  
`make[1]: *** [install-recursive] Error 1`  
`make[1]: Leaving directory '/usr/python/python/geos-3.9.0'`  
`make: *** [install] Error 2`  
  1. I even found a suggestion from the libgeos website to install it via

    sudo yum install -y amazon-linux-extras
    sudo amazon-linux-extras enable epel
    sudo yum search geos
    sudo yum install geos geos-devel

but that returned that there was nothing to install from the extras that would be "geos" or "geos-devel".

Has anyone successfully created one or got any suggestions I could try?

Jonnu
  • 1
  • 1
  • Solved this using my other non-ec2 VM with python 3.10 and then decided to change my lambda to 3.10 as well since this worked. `Path for python.zip = python/lib/python3.9/site-packages` Then just installed normally within a venv: `python3 -m venv env ` `source env/bin/activate` `mkdir python/lib/python3.9/site-packages` `cd python/lib/python3.9/site-packages` `pip install shapely -t .` `cd .. to folder before python folder` `zip -r python.zip python` The path that works for ie. requests didnt. (``requests.zip/python/libraries_installed_here``) – Jonnu May 03 '23 at 18:35
  • Hi, it's better to write a regular answer; comments are not suitable – pierpy May 03 '23 at 19:38

1 Answers1

0

Solved this using my other non-ec2 VM with python 3.10 and then decided to change my lambda to 3.10 as well since this worked. Path for python.zip = python/lib/python3.9/site-packages

Then just installed normally within a venv:

python3 -m venv env  
source env/bin/activate
mkdir python/lib/python3.9/site-packages 
cd python/lib/python3.9/site-packages  

pip install shapely -t .  

cd .. to folder before python folder  
zip -r python.zip python  

The path that works for ie. requests didnt work for some reason. (requests.zip/python/libraries_installed_here). Seems like the required dependencies are already inside also (duh), even though separate would be good too.

Jonnu
  • 1
  • 1