Windows python pre-commit getting ImportError sqlite

Viewed 1347

I'm trying to set up a pre-commit hook. To this end, I've created a .pre-commit-config.yaml like this:

repos:
-   repo: https://github.com/ambv/black
    rev: 19.10b0
    hooks:
    - id: black
      language_version: python3.7
-   repo: https://gitlab.com/pycqa/flake8
    rev: 3.7.9
    hooks:
    - id: flake8

Then, in my conda environment, I run pre-commit install, which runs without any erros. However, when I commit now, I'm getting

$ git commit -m "Format code using black + add hooks"
Traceback (most recent call last):
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\site-packages\pre_commit\__main__.py", line 1, in <module>
    from pre_commit.main import main
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\site-packages\pre_commit\main.py", line 13, in <module>
    from pre_commit.commands.autoupdate import autoupdate
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\site-packages\pre_commit\commands\autoupdate.py", line 14, in <module>
    from pre_commit.clientlib import InvalidManifestError
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\site-packages\pre_commit\clientlib.py", line 15, in <module>
    from pre_commit.error_handler import FatalError
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\site-packages\pre_commit\error_handler.py", line 10, in <module>
    from pre_commit.store import Store
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\site-packages\pre_commit\store.py", line 4, in <module>
    import sqlite3
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\sqlite3\__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "c:\users\mathis\anaconda3\envs\pvinspect36\lib\sqlite3\dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

Unfortunately, I cannot reproduce reproduce this error from the shell, because there, I can import sqlite3 seamlessly (using the same conda env). Any ideas how this can be solved?

1 Answers

this is a known issue with conda on windows -- I'd suggest using the official python.org pythons

conda does some interesting things with their linked DLLs which require special environment variables at runtime -- you can work around by ensuring your conda environment is always activated when working with pre-commit

you can find more information here: https://github.com/conda-forge/pre-commit-feedstock/issues/9


disclaimer, I'm the author of pre-commit

Related