dateparser
dateparser copied to clipboard
DateParser thorws error when imported on embedded Python.
The dateparser library uses a exec_module on the _strptime. This causes the import to fail when using the the embedded version of python as the import happens via zipimport and zipimport does not have exec_module() so the following error gets thrown on import dateparser
D:\DateParser Test\python-3.9.0-embed-amd64>python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dateparser
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\DateParser Test\python-3.9.0-embed-amd64\lib\site-packages\dateparser\__init__.py", line 3, in <module>
from .date import DateDataParser
File "D:\DateParser Test\python-3.9.0-embed-amd64\lib\site-packages\dateparser\date.py", line 9, in <module>
from dateparser.date_parser import date_parser
File "D:\DateParser Test\python-3.9.0-embed-amd64\lib\site-packages\dateparser\date_parser.py", line 5, in <module>
from .conf import apply_settings
File "D:\DateParser Test\python-3.9.0-embed-amd64\lib\site-packages\dateparser\conf.py", line 5, in <module>
from .parser import date_order_chart
File "D:\DateParser Test\python-3.9.0-embed-amd64\lib\site-packages\dateparser\parser.py", line 12, in <module>
from dateparser.utils.strptime import strptime
File "D:\DateParser Test\python-3.9.0-embed-amd64\lib\site-packages\dateparser\utils\strptime.py", line 57, in <module>
__strptime = patch_strptime()
File "D:\DateParser Test\python-3.9.0-embed-amd64\lib\site-packages\dateparser\utils\strptime.py", line 28, in patch_strptime
_strptime_spec.loader.exec_module(_strptime)
AttributeError: 'zipimporter' object has no attribute 'exec_module'
>>>
Steps to Reproduce
-
Download the python.zip file the link below https://www.python.org/ftp/python/3.9.0/python-3.9.0-embed-amd64.zip
-
Uncomment import site in the python39._pth
-
Download pip from https://bootstrap.pypa.io/get-pip.py and run python get-pip.py to install pip
-
pip install dateparser
-
Run python
-
import dateparser
-
error above is thrown.
Please do let me know if any further information is required to reproduce problem.
Thanks.
It looks like they’ve implemented exec_module
for zipimporter
in the upcoming Python 3.10. Assuming no one submits a pull request to fix this for earlier versions of Python, at least there’s that.
The same thing seems to happen when py2exe and similar is used. I tried changing the dateparser\utils\strptime.py so that checks whether 'exec_module' is a loader attribute and if not calls 'load_module' but this does not work.
I hit this also... can I specify an older version of Dateparser to get around it?
oh... and I have the same problem with 3.8
Should be fixed by https://github.com/scrapinghub/dateparser/pull/1069