I'm trying to create a development package for AWS Lambda. One of the modules I am using is praw which has a lot of dependencies such as urllib3 and requests.
I use the command pip install praw -t . in the folder where I need to use praw this installs all the dependencies as well. But whenever I try to import praw i get the error message
File "c:\Script\Modules\praw\reddit.py", line 23, in
from prawcore import ( ModuleNotFoundError: No module named 'prawcore
This happens despite prawcore being installed. If I go into that reddit.py file and replace that code with from Modules.prawcore import ( then it works but then another dependencies fails and I have to come in and put the Modules. bit in. Is there a way to get around this and make sure the dependencies are detected? Or is it some other problem?
Ah I think you need to deploy Lambda and all code packages as zip folder and upload them in AWS. Did you check that when you do pip install praw -t . you will get library folder? So, just zip that with lambda code and upload as a zip folder
Related
I've been trying to install the py2exe module (for Python 3) offline (it's a stand-alone network) without without installing any dependencies first (I couldn't find a list of dependencies anywhere).
When I try to install it, it runs into a module exception :
no module named py2exe_distutils
The file is in a .tar.gz format.
I use the pip install file in cmd while being in the file directory.
I would appreciate any help regarding this.
I think you need this:
https://github.com/py2exe/py2exe/releases/tag/v0.10.4.0
this file contain the offline setup 😁
image
I downloaded a project and am running through and installing all dependencies. At first I had errors regarding No module named utm and No module named paho. I solved these issues by going to C:\Users\me and using pip install paho-mqtt and pip install utm. Easy enough.
I then have this line "from mfa_msgs import Mission, WaypointList, MissionControl, ControlCommand, Status" and am getting a No module error here. mfa_msgs is a folder found in the project I downloaded that contains the Mission, WaypointList, etc. files. Where do I need to put the mfa_msgs folder in order to be able to access them?
Appreciate your time!
I am writing a python script which will run in AWS as lambda function. Since it needs to connect to a Postgres database, library psycopg2 is required. It seems the standard psycopg2 does not work with AWS lambda. I downloaded it from this git repo.
I am using virtualenv for all the dependencies, so I copied the psycopg2-3.6 folder from the downloaded package to [myproject]/env/Lib/site-packages. In my main script this library is imported
import psycopg2
However when I run it in PyCharm, I got error:
File "C:\Users\dxx0111\WorkSpace\iq-iot-lambda\app.py", line 2, in <module>
import psycopg2
File "C:\Users\dxx0111\WorkSpace\iq-iot-lambda\env\lib\site-packages\psycopg2\__init__.py", line 50, in <module>
from psycopg2._psycopg import ( # noqa
ModuleNotFoundError: No module named 'psycopg2._psycopg'
Based on the error message, it looks like it was able to locate the directory of psycopg2 under virtual environment package folder. It just couldn't find psycopg2._psycopg. What am I missing here?
As it turns out, the psycopg2 library downloaded from that link only works on Amazon Linux because that is where the package was compiled on. It doesn't work on my Windows machine. In order to make it work locally, I had to install with pip install psycopg2 to my virtual env. When I deploy to AWS Lambda though, I make the zip with the downloaded library. So different psycopg2 in different platform. Now it works in both places.
I'm trying to install PyDrive [a wrapper library of the google drive api for python] and pip is giving me this error. It did the same thing when trying to install things like matplotlib or mega.py [a mega.nz api for python].
Here's the error:
Anyone got a clue what's going on?
Cheers
You could try renaming that pip.py to something else.
There is a library called pip somewhere on your system (and it may also be bundled within pip.exe). That is different from the "entry point" script that actually runs pip from the command line. When you run pip, it will try to import the library called pip. If there is a script called pip.py in the Scripts directory (representing the entry-point script, not the library), it may import that instead of the real library. If this is indeed the problem, renaming pip.py to something else will remove the name conflict and allow pip to properly import the library it needs.
I'm not sure how you wound up with pip.py in your Scripts directory in the first place. I don't think it should be there. My Python installation on Windows doesn't have it.
How do we create a pymssql package for lambda. I tried creating it using
pip install pymssql -t . When I run my lambda function it complaints saying that
Unable to import module 'lambda_function': No module named lambda_function
I follow the steps on this link
http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
I have a windows machine
Glad that it worked for you, could you please share the working process for your, me too tried different trial and error steps and ended up with the following one which is working fine in AWS Lambda, I am using PYMSSQL package only.
1) did 'pip install pymssql' on amazon EC2 instance as under the hood Amazon uses Linux AMIs to run their Lambda functions.
2) copied the generated .so files and packaged inside the Lambda deployment package hope this will helps others as well who are searching for the solution.
Hope this will help you further, can you please share what you did to connect to MSSQL server using AWS Lambda.
Below is the folder structure of my lambda deployment package
Windows "pymssql" file not supported in AWS lambda since lambda running on Amazon Linux 2.
So we can get Linux-supported wheel files from the following official "pymssql" website download link. You look for "manylinux_2_24_x86_64" version file with the required python version. At the time of writing python 3.9 is the latest version. So download file will be "pymssql-2.2.2-cp39-cp39-manylinux_2_24_x86_64.whl".
Once download the wheel file execute the below command
pip install {path of downloaded wheel file} -t {target folder to store this package}
Example
pip install pymssql-2.2.2-cp39-cp39-manylinux_2_24_x86_64.whl -t /package
Finally i could do it. It didnt worked with windows packages so used ubuntu to package freetds.so file and it worked.
Along with pymssql try to import cypthon.
Just a quick update for new changes.
There seems to be some issue with python 3.9 AWS lambda, it throws the below error on pymssql==2.2.3.
{
"errorMessage": "Unable to import module 'index': No module named
'pymssql._pymssql'",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
but if I change the python version to 3.8, the error vanishes.