NumPy setup / import issue in lambda function - python

Runtime python 3.7 w/ compatible runtime 3.7
I keep getting Import error when trying to test API in lambda function
PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the numpy C-extensions failed. This error can happen for\nmany reasons, often due to issues with your setup or how NumPy was\ninstalled.\n\nWe have compiled some common reasons and troubleshooting tips at:\n\n https://numpy.org/devdocs/user/troubleshooting-importerror.html\n\nPlease note and check the following:\n\n * The Python version is: Python3.7 from \"/var/lang/bin/python3.7\"\n * The NumPy version is: \"1.21.5\"\n\nand make sure that they are the versions you expect.\nPlease carefully study the documentation linked above for further help.\n\nOriginal error was: No module named 'numpy.core._multiarray_umath'\n",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
I have tried adding numpy pip install inside docker, yet the issue still persists...
The dockfile engine used is amazonlinux:2
Any way of solving this weird issue?

Based on the comments.
The solution was to use Numpy layer provided by AWS.

Related

Python + VSCode not playing nice with Numpy

I regularly use python on my PC (Spyder, Juptyer etc) without issue. I've recently installed VSCode, to take advantage of its debug features.
However, I can't seem to get it to play nice with Numpy. Running a script simply with:
import numpy as np
Exception has occurred: ImportError
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "C:\ProgramData\Anaconda3\python.exe"
* The NumPy version is: "1.21.5"
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
Also:
I have these installed and enabled:
This works in Spyder, Jupyter etc. And I'm using the 'base' conda environment, and can see that numpy is installed in the Packages list.
Any help on fixing this (so I can debug without using 1000x prints!) is much appreciated!

Python4Delphi can't import numpy

I was curious about Python4Delphi and installed it and looked through the demos a bit. Now I wanted to install Numpy via CMD with pip this went well without errors. but now when I enter the following code in DEMO01 of Python4Delphi I get an error message. If I enter the same code in python it works. How can i solve this?
How i installed Numpy:
pip install numpy
Example code:
import numpy as np
print(np .__version__)
The error i got:
AttributeError: partially initialized module 'numpy' has no attribute '__version__' (most likely due to a circular import). Did you mean: '_version'?
The versions:
Delphi 11,
Python 3.10.4,
Pip 22.1,
Numpy 1.22.4 and
Win64
if i forgot some information let met know.
Can you check you're using the same versions of python using both methods by checking what this returns...
import sys
for p in sys.path:
print(p)
Carefully compare the output of that little bit of code as it'll point out any obvious differences.
From my experiments if you've got more than one Python on your system things can get weird with Python4Delphi so the above should provide evidence if this is your situation.
Importing numpy should actually cause an exception anyway, just not the one you mention in your question. Importing Numpy in demo01 will trigger a div by zero unless you add a MaskFPUExceptions(True); before you execute the python
If you use an embedded Python things will get even worse for you as you'll need to set some additional paths to import anything. The only way I've found to do this properly ATM is by addending paths to sys.path in a small python stub with paths constructed relative to the embedded root (Lib and Lib/site-packages incidentally)

Installing Python Package in AWS Lambda Layer

I have a python script which is running on my local machine and I want to move it to AWS Lambda for periodic execution. I have 3 import statements in the script for which I am adding layers but facing some issues.
from googleapiclient.discovery import build
import pandas as pd
from datetime import date
For googleapiclient api, I downloaded it in a folder and uploaded to AWS layer and lambda is able to find this module. I wanted to use this along with AWS Data wrangler package but running into layer size restriction issues. So I downloaded pandas to the same folder as google api and then uploaded the zip file to layer. But now I am get a numpy dependency error though numpy was downloaded as part of pandas install. Two folders as part of my libraries folder are numpy, numpy-1.22.0.dist-info which is correct version as per error message below. I also tried downloading numpy separately in same package but that's also not working. The Python version that I am using in Lambda is 3.7.
Please let me know if I am missing something and if this is the correct approach for installing python packages for AWS Lambda. There are some solutions available with regards to using a container for this but I am not well versed with containers. So just wanted to check if there is some fix through which I can achieve this or is containers the way to go about it.
Below is the error message:
Response { "errorMessage": "Unable to import module 'lambda_function':
Unable to import required dependencies:\nnumpy: \n\nIMPORTANT: PLEASE
READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the
numpy C-extensions failed. This error can happen for\nmany reasons,
often due to issues with your setup or how NumPy was\ninstalled.\n\nWe
have compiled some common reasons and troubleshooting tips at:\n\n
https://numpy.org/devdocs/user/troubleshooting-importerror.html\n\nPlease
note and check the following:\n\n The Python version is: Python3.7
from "/var/lang/bin/python3.7"\n The NumPy version is:
"1.22.0"\n\nand make sure that they are the versions you
expect.\nPlease carefully study the documentation linked above for
further help.\n\nOriginal error was: No module named
'numpy.core._multiarray_umath'\n", "errorType":
"Runtime.ImportModuleError", "stackTrace": [] }
Function Logs START RequestId: d......-........-.....d
Version: $LATEST ERROR Runtime.ImportModuleError: Unable to import
module 'lambda_function': Unable to import required dependencies:
numpy: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS
ISSUE! Importing the numpy C-extensions failed. This error can happen
for many reasons, often due to issues with your setup or how NumPy was
installed. We have compiled some common reasons and troubleshooting
tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html Please
note and check the following:
The Python version is: Python3.7 from "/var/lang/bin/python3.7" The
NumPy version is: "1.22.0" and make sure that they are the versions
you expect. Please carefully study the documentation linked above for
further help. Original error was: No module named
'numpy.core._multiarray_umath' Traceback (most recent call last): END
RequestId: de72............................6d REPORT RequestId:
de72............................6d Duration: 1.68 ms Billed
Duration: 2 ms Memory Size: 128 MB Max Memory Used: 55 MB Init
Duration: 570.09 ms Request ID de72............................6d
Regards, Dbeings
The issue was that I was building the pandas package on windows machine and uploading it to AWS layer. Building the package on EC2 and then putting it on AWS layer fixed the issue.

'numpy.core._multiarray_umath' in Eclipse IDE

I am running Eclipse IDE 4.20.0 with a PyDev Interpreter on Windows10. I am trying try to get [Camelot][1] to run within my script but continue to get the error-
"Original error was: No module named 'numpy.core._multiarray_umath'"
For each, I have used pip install to install camelot, tabula-py, numpy, pandas, etc. and all of them seemed to install appropriately. My Eclipse Project Properties PYTHONPATH is pointed to the install location and I haven't had issues with other libraries I have installed previously.
The Python version is: Python3.7
The NumPy version is: "1.21.5"
I also tried reverting numpy to an older version (1.15.1) but had no success there based on other posts that I have seen here on stackoverflow. Additionally, I have read the numpy support site that is listed in the error below but can't find anything that would be of note in my system as an issue...
Ultimately, I am attempting to read tables from a PDF in python but it seems that the libraries available (camelot, tabula, etc.) all give me the same issue with numpy. Any suggestions here would be greatly appreciated.
The full error that I am getting is -
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed.
This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
The Python version is: Python3.7 from "C:\Users~~~\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe"
The NumPy version is: "1.21.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'

Not able to add pandas in aws layer and getting error

I'm getting error when I import pandas/numpy in lambda function:
I added pandas/numpy as a aws layer also I have added pymysql in same way, and it's working fine.
Working on windows 10,
Using python3.7 same in lambda also
Building zip package using pip install pandas -t
In dir - python\lib\python3.7\site-packages
{
"errorMessage": "Unable to import module 'lambda_function': \n\nIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the numpy C-extensions failed. This error can happen for\nmany reasons, often due to issues with your setup or how NumPy was\ninstalled.\n\nWe have compiled some common reasons and troubleshooting tips at:\n\n https://numpy.org/devdocs/user/troubleshooting-importerror.html\n\nPlease note and check the following:\n\n * The Python version is: Python3.7 from \"/var/lang/bin/python3.7\"\n * The NumPy version is: \"1.19.1\"\n\nand make sure that they are the versions you expect.\nPlease carefully study the documentation linked above for further help.\n\nOriginal error was: No module named 'numpy.core._multiarray_umath'\n",
"errorType": "Runtime.ImportModuleError"
}
zip of the package should be done in the build folder, even though you install the packages in the site-packages
https://www.youtube.com/watch?v=zrrH9nbSPhQ - has some good steps to follow through.
Pandas could be a huge zip file, that lambda layers might not support. You might want to check for pandas- example pandas-xlrd.

Categories

Resources