nbQA-dev / nbQA

Run ruff, isort, pyupgrade, mypy, pylint, flake8, and more on Jupyter Notebooks
https://nbqa.readthedocs.io/en/latest/index.html
MIT License
1.01k stars 39 forks source link

ipython import error #851

Closed lennart-scale closed 3 weeks ago

lennart-scale commented 4 months ago

Hi, I have nbqa version 1.85 installed and would like to use it as a pre-commit hook. I am using python 3.8 and manually installed ipython 8.12.0. this is my .pre-commit-config.yaml file

repos:
  - repo: https://github.com/psf/black
    rev: 22.12.0
    hooks:
      - id: black
        name: "python:black"
        entry: black --config .black.toml
        additional_dependencies: ['click<=8.0.4'] 
  - repo: https://github.com/PyCQA/flake8
    rev: 6.0.0
    hooks:
      - id: flake8
        name: "python:flake8"
  - repo: https://github.com/pycqa/isort
    rev: 5.12.0
    hooks:
      - id: isort
        args: ["--settings-path", ".isort.cfg"]
        name: "python:isort"
  - repo: https://github.com/nbQA-dev/nbQA
    rev: 1.8.5
    hooks:
      - id: nbqa-black
        name: "ipynb:black"
        entry: black --config .black.toml
        additional_dependencies: [black==22.12.0]
      - id: nbqa-flake8
        name: "ipynb:flake8"
        additional_dependencies: [flake8==6.0.0]
      - id: nbqa-isort
        name: "ipynb:isort"
        args: ["--settings-path", ".isort.cfg"]
        additional_dependencies: [isort==5.12.0]

When running the hook on a specific ipynb file, pre-commit run --file X.ipynb, I keep getting the following error trace:

- hook id: nbqa-black
- exit code: 1
Traceback (most recent call last):
  File "/home/ubuntu/.cache/pre-commit/reporw3b8p3t/py_env-python3.8/bin/black", line 8, in <module>
    sys.exit(patched_main())
  File "src/black/__init__.py", line 1415, in patched_main
  File "/home/ubuntu/.cache/pre-commit/reporw3b8p3t/py_env-python3.8/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/ubuntu/.cache/pre-commit/reporw3b8p3t/py_env-python3.8/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/ubuntu/.cache/pre-commit/reporw3b8p3t/py_env-python3.8/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ubuntu/.cache/pre-commit/reporw3b8p3t/py_env-python3.8/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/ubuntu/.cache/pre-commit/reporw3b8p3t/py_env-python3.8/lib/python3.8/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "src/black/__init__.py", line 562, in main
  File "src/black/__init__.py", line 662, in get_sources
  File "src/black/handle_ipynb_magics.py", line 61, in jupyter_dependencies_are_installed
  File "/home/ubuntu/.cache/pre-commit/reporw3b8p3t/py_env-python3.8/lib/python3.8/site-packages/IPython/__init__.py", line 30, in <module>
    raise ImportError(
ImportError: 
IPython 8.13+ supports Python 3.9 and above, following NEP 29.
IPython 8.0-8.12 supports Python 3.8 and above, following NEP 29.
When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
Python 3.3 and 3.4 were supported up to IPython 6.x.
Python 3.5 was supported with IPython 7.0 to 7.9.
Python 3.6 was supported with IPython up to 7.16.
Python 3.7 was still supported with the 7.x branch.

See IPython `README.rst` file for more information:

    https://github.com/ipython/ipython/blob/main/README.rst

And the same error appears for ipynb:flake8, ipynb:isort. The error message indicates that the ipython version is not compatible with python 3.8. However, the ipython I installed, 8.12.0, is explicitly compatbile. Does something else happen under the hood or does nbqa require a specific ipython/min python version?

MarcoGorelli commented 3 weeks ago

thanks for the report

no idea, sorry, looks like an issue with your python environment

closing then as this doesn't seem actionable, but will reopen if further details are provided