简体   繁体   English

AWS Lambda 导入 psycopg2 - 无法导入模块“app”:没有名为“psycopg2._psycopg”的模块

[英]AWS Lambda Importing psycopg2 - Unable to import module 'app': No module named 'psycopg2._psycopg

I am trying to use the psycopg2 library with AWS lambda in my Pycharm IDE on Windows 10.我正在尝试在我的 Pycharm Windows 10 上的 lambda IDE 中使用 psycopg2 库。

I have tried all versions of Python listed in this repository and I still always get the following error:我已经尝试了这个存储库中列出的 Python 的所有版本,但我仍然总是收到以下错误:

{"errorMessage": "Unable to import module 'app': No module named 'psycopg2._psycopg'", "errorType": "Runtime.ImportModuleError", "stackTrace": []}

I have tried this solution where we install aws-psycopg2 but it did not work.我已经在安装aws-psycopg2地方尝试过这个解决方案,但它没有用。 As per this solution, I have ensured that my local Python runtime and the Lambda runtime are the same and I still get the error.根据解决方案,我已确保我的本地 Python 运行时和 Lambda 运行时相同,但我仍然收到错误。

I have made sure that my Python version is 64 bit as per this answer根据答案,我已确保我的 Python 版本为 64 位

Hey incase it still didn't work, i faced the same issue here's what i did:嘿,万一它仍然不起作用,我遇到了同样的问题,这就是我所做的:

  • ran this command:运行此命令:
  • pip install --platform=manylinux1_x86_64 --only-binary=:all: psycopg2-binary --target psycopg-binary/python/lib/python3.8/site-packages pip 安装 --platform=manylinux1_x86_64 --only-binary=:all: psycopg2-binary --target psycopg-binary/python/lib/python3.8/site-packages

  • created a lambda layer with the above package (pyscopg-binary) and added it to the lambda function使用上面的 package (pyscopg-binary) 创建了一个 lambda 层,并将其添加到 lambda function
  • make sure runtimes are correct ( at first i had the lamda layer runtime 3.9 and the function 3.9, then i switched both to 3.8 and it worked)确保运行时是正确的(起初我有 lamda 层运行时 3.9 和 function 3.9,然后我切换到 3.8 并且它工作)
  • Im not absolutely sure aside from the runtimes which of the packages caused it to work (since i did multiple things in one step: added aws-psycopg2 to the requirements.txt in addition to changing runtime, hence im not sure if the aws-psycopg2 had anything to do with it working:), but i think that it has nothing to do with it, so it should work without it).除了运行时,我不确定是哪个包导致它工作(因为我在一个步骤中做了很多事情:除了更改运行时外,还向 requirements.txt 添加了 aws-psycopg2,因此我不确定 aws-psycopg2 是否与它的工作有任何关系:),但我认为它与它无关,所以没有它它应该可以工作)。

hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM