Executing python script which depends on numpy and cv2 - aws-lambda

I'm executing python script in AWS lambda and I want to use numpy and cv2 in that python script. Is there a way to include numpy and cv2 into lambda zip package?

this blog post seems to answer your question.
python on aws lambda
Namely, its about creating a virtualenv and executing the python code from within that context.

Related

Azure functions (cloud): Install cython dependent module

I'm trying to install/import a cython dependent module [ZigZag] into my python function on Azure functions (Linux platfrom), I'm working via Windows 8.1 (VSCode), Running Python 3.6 on both local machine and azure functions.
I tried including Cython in the requirements.txt file, this errors out during deployment (seems installation of external modules happens somewhat in parallel)
I tried creating a '.toml' file, no luck.
I also tried the idea found here Python google cloud function deployment failure - Madmom pip package still didn't work.
Finally I decided to deploy the function first (with cython included in the 'requirements.txt' file) without the zigzag module, and then in my python script use subprocess.Popen() to do a pip install zigzag and import it before the rest of the function runs.
This is where I get stuck. In my python file I have these lines included to do the above:
#function to be called in azure __init__.py file
def f....:
# check for zigzag
try:
import zigzag
except ImportError:
subprocess.Popen(["pip", "install", "ZigZag"], shell=True)
finally:
import zigzag
.
.
.
rest of the function...
This deploys successfully to azure functions, however it fails during execution with the error:
Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException :
Result: Failure Exception: ModuleNotFoundError: No module named 'zigzag
Any idea's how to do this correctly?
NB: This issue occurs on google cloud functions as well.
I see this is related to https://learn.microsoft.com/en-us/answers/questions/152557/index.html
As per the thread, the latest version for ZigZag is 0.2.2 and the supported python version is 3.5: https://pypi.org/project/ZigZag/
The azure function supports 3.6 and above python version which will make it incompatible. You can try installing the latest cython using requirements.txt and it will work as expected. But when you try to install ZigZaG it tries to find the dependency of cython package (Cython==0.26.1) that is compatible with it therefor it throws the error that cython package not found.

Creating Python 3.6 AWS Lambda package

My OS is win 10 Home.
I have a Python 3.6 script that updates an MSSql DB, using pymssql. The script works fine locally.
Now I need to upload it as aws lambda, so I followed this using the cmd:
python -m venv .
Scripts\activate
pip install pymssql
Then I copied my py function to the Lib\site-packages dir, ziped all the dir content and uploaded it to the Lambda service.
The result was this error:
Unable to import module 'validationLambda': No module named 'pymssql'
How to fix this?
I am not strong with Windows environments but you should probably try to do the opposite.
Copy the Lib\site-packages\pymssql directory to the root of your package (same level with your_function.py
Try to import cython along with pymssql.

How to use Normal constructor correctly in pymc3?

When I use pymc3 to construct a normal distribution, I got error message. How to solve this problem?
I installed PyMC3 with windows Anaconda (version Anaconda3-2019.03-Windows-x86_64.exe). And running codes from official pymc3 tutorial "Getting started with PyMC3".
I tried to build a normal distribution with Normal constructor pm.Normal(). The codes are listed below
import numpy as np
import pymc3 as pm
basic_model = pm.Model()
with basic_model:
# Priors for unknown model parameters
alpha = pm.Normal('alpha', mu=0, sigma=10)
But got error message as the following:
AttributeError: module 'numpy.core.multiarray' has no attribute '_get_ndarray_c_version'
The problem is solved by removing theano 1.0.3 from Anaconda and performing pip install the latest version >=1.0.4.

Numpy and Pandas Not Working in Jupyter Notebook on Mac

I have both Python 2.7 and 3.6 working on my machine. Numpy and Pandas both load, for either version of Python, in the terminal. However, when I try to access them from inside Jupyter notebook, I get the following error messages:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-4ee716103900> in <module>()
----> 1 import numpy as np
ModuleNotFoundError: No module named 'numpy'
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-af55e7023913> in <module>()
----> 1 import pandas as pd
ModuleNotFoundError: No module named 'pandas'
Here is a screenshot of the problem as well:
If you look in the top right hand corner of the screenshot, you will notice where it says "Python3". I have seen video tutorials on Jupyter where clicking on that button generates a drop down list, allowing users to select alternate versions of Python. However, when I click on that button, nothing happens.
I noticed that a similar question was asked before here:
numpy & pandas 'ModuleNotFoundEror' in Jupyter notebook (Python 3)
However, very little information was provided and no resolution seems to have been found.
Another similar question provided a hint at an answer that was slightly more promising. It suggested running the following code both from terminal and from inside Jupyter, to make sure they match.
import sys; sys.executable
failed to import numpy as np when I worked with jupyter notebook
From terminal using Python 2.7.10>>
import sys; sys.executable
'/usr/bin/python'
From terminal using Python 3.6.1>>
import sys; sys.executable
'/usr/local/bin/python3'
From Jupyter>>
'/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6'
Have you checked this solution:
Failure to import numpy in Jupyter notebook ?
In your Jupyter screenshot, you're using a Python 3 kernel.
Make sure you have NumPy (and any others you might want to use) installed in your selected Python 3 environment.

Error "matplotlib is not a package" on Mac problems

Getting the No module named 'matplotlib.pyplot'; matplotlib is not a package error when trying to run:
import matplotlib.pyplot
plt.plot([1,2,3,4],[4,7,8,12])
plt.show()
Im running python 3.3, and have installed the correct matplotlib, and six library. i have checked this by running pip list.
I have also tried running the file in terminal, and when i do this the error changes from matplotlib is not a module to no module named pyplot.

Resources