astro
astro copied to clipboard
Regex not working
When trying to use the dateparser
module w/ AWS Lambda (Python 3.6, Zappa 0.44.3), I'm seeing an error in CloudWatch, after trying to import dateparser (the upper portion of this trace has been omitted):
File "/var/task/dateparser/__init__.py", line 4, in <module>
from .date import DateDataParser
File "/var/task/dateparser/date.py", line 8, in <module>
import regex as re
File "/var/task/regex.py", line 400, in <module>
import _regex_core
File "/var/task/_regex_core.py", line 21, in <module>
import _regex
ModuleNotFoundError: No module named '_regex'
Regex has versions newer than the one currently in lambda-packages (lambda-packages: 2016.8.27, regex (current): 2017.12.12), and appears to only be pre-built for python 2.7. Perhaps the solution is simply upgrading the pre-built regex? Including a pre-built version for python 3.6?
Having the same issue. Using MayaDT which uses dateparser. Any workarounds until the lambda-package is updated?
Python 3.6.3 and Zappa 0.45.1
import maya
File "/var/task/maya/__init__.py", line 1, in <module>
from .core import *
File "/var/task/maya/core.py", line 18, in <module>
import dateparser
File "/var/task/dateparser/__init__.py", line 4, in <module>
from .date import DateDataParser
File "/var/task/dateparser/date.py", line 8, in <module>
import regex as re
File "/var/task/regex.py", line 400, in <module>
import _regex_core
File "/var/task/_regex_core.py", line 21, in <module>
import _regex
ModuleNotFoundError: No module named '_regex'
None known, for now, but I also haven't done much research into this. Left this here in the hopes that the maintainer(s) of lambda-packages would have a quick fix.
fyi, same problem after pipenv update
today. I'm using the slim_handler
too. Any one have a workaround?
I'm just having the same issue right now when upgrade a project from python 2.7 to 3.6, zappa==0.45.1
As best I can tell, Regex maintains source code for py2 and py3 in different directories (the "regex_2" and "regex_3" directories, check them out here ), and the _regex
module is compiled in (and run from) these different directories depending on the intended Python version. So, if it was compiled for 2.7, the compiled module should by in "regex_2", and if you run with 3.6, it seems reasonable that python isn't able to find the compiled module in "regex_3".
Seems like we definitely need a version compiled for python 3.6. I just provisioned a new EC2 instance running Amazon Linux (with ideas of compiling for python 3 on that machine, copying compiled binary back to local, uploading+testing on Lambda, and submitting PR with compiled binary), but I'm running into issues on my end, and don't think I'll be able to complete this quickly. If someone else knows how to get this done, feel free.
@Miserlou
Is there any update to this issue? I just got bit by this while trying to install a project with Django Zinnia blog to AWS Lambda using Zappa.
I submitted a pull request that attempts to fix this: https://github.com/Miserlou/lambda-packages/pull/76
@ariwbolton
Hey, #76 was merged but the issue is still open. I just stumbled on this problem. Was #76 a sufficient fix?
Hi there, issue still seems to exist. I get the "No module named '_regex' " when I try to import dateparser on aws lambda (both on python3 and 2.7) Is there a workaround?
I am also presently seeing "No module named '_regex'" on Python 3 when including dateparser with Lambda and would be interested in an answer if anyone's found one.
For those considering workarounds, my answer was including the dateutil.parser library, which functions in Lambda and will find dates, in place of the dateparser library.
I've ran into this issue recently and for me I found that it was related to a 'Invalid ELF header' instead. When I ran 'pip install dateparser' it created dateparser to run on my Mac platform instead of the AWS platform. Which just means the binarys that 'pip install' created were for a different none AWS platform.
To fix, I used a docker container to build '_regex' in Python 2.7 for AWS's Debian-based Linux platform. Steps from here
- install docker
- docker run -v
:/working -it --rm ubuntu - apt-get update; apt-get install python-pip; apt-get install zip
- cd working
- pip install -t .
- zip -r deployable.zip .
- Deploy deployable.zip to lamdba
I hope this saves time for anyone who has this issue in the future.
Same issue with Python 3.7 in AWS Lambda. Any updates ? "errorMessage": "Unable to import module 'handler': No module named 'regex._regex'",
i am also getting exactly the same error message in aws lambda Same issue with Python 3.7 in AWS Lambda. "errorMessage": "Unable to import module 'handler': No module named 'regex._regex'",
Also got
"errorMessage": "Unable to import module 'handler': No module named 'regex._regex'",
problem was next: my OS use Python 3.6 as default Python interpreter
And I've install requirements via
pip3 install -r requirements.txt -t aws-lib
after installing Python 3.7 from source and change command above on
pip3.7 install -r requirements.txt -t aws-lib
problem was solved
hope it helps for someone
note, doing the command from @chinskiy has an unattended consequence, the binary installed by your requirements.txt now have #!/usr/bin/python3.7
as their shebang, and so can't be called anymore from lambda, as there's not /usr/bin/python3.7
in lambda container, only /usr/bin/python3
:(
also if you were already on python3.7, it does not solve the problem
Any solution to this? I am using dill
library and when I try to load I am getting the following error:
import dill as pickle
error:
loading spacy tokenizers...
Traceback (most recent call last):
File "translate_file.py", line 148, in <module>
main()
File "translate_file.py", line 118, in main
fields = create_fields(opt)
File "/home/composition_func/Process.py", line 75, in create_fields
SRC = pickle.load(open(f'{opt.load_weights}/SRC.pkl', 'rb'))
File "/home/anaconda3/envs/py36/lib/python3.7/site-packages/dill/_dill.py", line 270, in load
return Unpickler(file, ignore=ignore, **kwds).load()
File "/home/anaconda3/envs/py36/lib/python3.7/site-packages/dill/_dill.py", line 472, in load
obj = StockUnpickler.load(self)
File "/home/anaconda3/envs/py36/lib/python3.7/site-packages/dill/_dill.py", line 826, in _import_module
return __import__(import_name)
ModuleNotFoundError: No module named '_regex'
I have regex installed. And don't know what's causing the problem. I used to be able to load using the same code but now I'm getting this error.
This issue still exist. I am using 'dateparser' module with my Python 3.7 and getting same error in AWS Lambda function console.
I had the same issue when deploying to AWS Lambda and the solution was to use the same version of Python while building dependency packages as is on AWS Lambda. For example if AWS Lambda runs Python 3.7 you have to use the Python 3.7 when building the packages that you will upload to Lambda.
Hey, I got the same issue. I think it comes from cython : the package has to be compiled in the same environment as the one provided by lambda. To solve it, I launched an EC2 instance using "amzn-ami-hvm-2018.03.0.20200918.0-x86_64-gp2": 1.- connect using ssh 2.- install python3 (https://gist.github.com/niranjv/f80fc1f488afc49845e2ff3d5df7f83b << update python version) 3.- pip3 install --target ./package myLibrary --no-binary=regex 4.- zip the library like in aws doc https://docs.aws.amazon.com/lambda/latest/dg/python-package.html 5.- disconnect from ec2 and download the file using "scp -i "sshkeyfile" server:ficher myComputer/my_func.zip" I hope it will be usefull.
I had same problem due to dateparser but resolved but building it using lambda docker runtime image
docker run -v "$PWD":/var/task "lambci/lambda:build-python3.6" /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.6/site-packages/; exit"
ANy update on this?
Hi @hafizSiddiq7675 the newly updated repo is here (https://github.com/zappa/Zappa). I didn't see this issue there so you could create one there and reference this issue there.