dateparser icon indicating copy to clipboard operation
dateparser copied to clipboard

DateParser thorws error when imported on embedded Python.

Open sudeepjd opened this issue 3 years ago • 5 comments

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

  1. Download the python.zip file the link below https://www.python.org/ftp/python/3.9.0/python-3.9.0-embed-amd64.zip

  2. Uncomment import site in the python39._pth

  3. Download pip from https://bootstrap.pypa.io/get-pip.py and run python get-pip.py to install pip

  4. pip install dateparser

  5. Run python

  6. import dateparser

  7. error above is thrown.

Please do let me know if any further information is required to reproduce problem.

Thanks.

sudeepjd avatar Dec 02 '20 08:12 sudeepjd

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.

Gallaecio avatar Dec 16 '20 16:12 Gallaecio

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.

johns1c avatar Oct 04 '21 21:10 johns1c

I hit this also... can I specify an older version of Dateparser to get around it?

petersilva avatar Mar 21 '22 14:03 petersilva

oh... and I have the same problem with 3.8

petersilva avatar Mar 21 '22 14:03 petersilva

Should be fixed by https://github.com/scrapinghub/dateparser/pull/1069

georgevreilly avatar Aug 24 '22 14:08 georgevreilly