linux 如何为Shapely 2.0(Python3.9)创建AWS Lambda层?

axkjgtzd  于 2023-05-06  发布在  Linux
关注(0)|答案(1)|浏览(204)

我一直在尝试为Lambda创建一个层,以便在运行时Python 3.9中使用shapely。出于某种原因,lambda总是返回错误:lambda_function': No module named 'shapely.lib
所以我的.zip文件可能有问题。我已经安装在路径shapely.zip/python/..
以下是我到目前为止所做的:
1.查找依赖项,并最终在python3 venv中压缩在一起:shapely,geos,pyproj和numpy像这样:
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
我还尝试了pip install shapely,但返回了Nothing to do
1.尝试altinstalling python3.9 on an ec2(with amazon linux 2)并在虚拟环境中运行它,但ec2一直告诉我python3.9是一个未知命令。我以前不得不与层层斗争,但这似乎是迄今为止最臭名昭著的。
1.我还注意到,通过运行“pip 3 install geos”,我可能安装了一个错误的版本,所以我尝试安装geos 3.9的tar.bz2,并安装它,就像我从互联网上找到的一样:
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
但这给了我一个奇怪的错误:

`/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.我甚至从libgeos网站上找到了一个建议,通过
sudo yum install -y amazon-linux-extras
sudo amazon-linux-extras enable epel
sudo yum search geos
sudo yum install geos geos-devel
但返回的是,没有任何安装从额外的将是“geos”或“geos-devel”。
有没有人成功地创建了一个或有任何建议,我可以尝试?

flvlnr44

flvlnr441#

我使用我的另一个非ec2 VM和python 3.10解决了这个问题,然后决定将我的lambda也改为3.10,因为这很有效。Path for python.zip = python/lib/python3.9/site-packages
然后在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

为IE工作的路径。由于某些原因,请求没有起作用。(requests.zip/python/libraries_installed_here)。看起来所需的依赖已经在里面了(duh),即使分开也很好。

相关问题