Skip to content

DateParser throws error when imported on embedded Python. #849

@sudeepjd

Description

@sudeepjd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions