Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateParser throws error when imported on embedded Python. #849

Closed
sudeepjd opened this issue Dec 2, 2020 · 5 comments · Fixed by #1069
Closed

DateParser throws error when imported on embedded Python. #849

sudeepjd opened this issue Dec 2, 2020 · 5 comments · Fixed by #1069

Comments

@sudeepjd
Copy link

sudeepjd commented Dec 2, 2020

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.

@Gallaecio
Copy link
Member

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.

@johns1c
Copy link

johns1c commented Oct 4, 2021

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.

@petersilva
Copy link

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

@petersilva
Copy link

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

@georgevreilly
Copy link
Contributor

Should be fixed by #1069

@wRAR wRAR changed the title DateParser thorws error when imported on embedded Python. DateParser thкows error when imported on embedded Python. Dec 9, 2022
@wRAR wRAR changed the title DateParser thкows error when imported on embedded Python. DateParser throws error when imported on embedded Python. Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants