question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleNotFoundError: Command `doctest` not found by nbqa

See original GitHub issue

How do I use nbqa with doctest? I tried nbqa doctest mynb.ipynb and got an error ModuleNotFoundError: Command doctest not found by nbqa I can run doctest if I do nbconvert then python -m doctest mynb.ipynb

% nbqa --version
nbqa 0.3.3
% nbqa doctest mynb.ipynb
Traceback (most recent call last):
  File "/Users/ntaylor/src/nanml-notebook/docs/venv/bin/nbqa", line 8, in <module>
    sys.exit(main())
  File "/Users/ntaylor/src/nanml-notebook/docs/venv/lib/python3.8/site-packages/nbqa/__main__.py", line 531, in main
    output_codes = [
  File "/Users/ntaylor/src/nanml-notebook/docs/venv/lib/python3.8/site-packages/nbqa/__main__.py", line 532, in <listcomp>
    _run_on_one_root_dir(i, cli_args, configs, project_root)
  File "/Users/ntaylor/src/nanml-notebook/docs/venv/lib/python3.8/site-packages/nbqa/__main__.py", line 474, in _run_on_one_root_dir
    out, err, output_code, mutated = _run_command(
  File "/Users/ntaylor/src/nanml-notebook/docs/venv/lib/python3.8/site-packages/nbqa/__main__.py", line 355, in _run_command
    raise ModuleNotFoundError(_get_command_not_found_msg(command))
ModuleNotFoundError: Command `doctest` not found by nbqa.

Please make sure you have it installed in the same Python environment as nbqa. See
e.g. https://realpython.com/python-virtual-environments-a-primer/ for how to set up
a virtual environment in Python.

Since nbqa is installed at /Users/ntaylor/src/nanml-notebook/docs/venv/lib/python3.8/site-packages/nbqa and uses the Python executable found at
/Users/ntaylor/src/nanml-notebook/docs/venv/bin/python, you could fix this issue by running `/Users/ntaylor/src/nanml-notebook/docs/venv/bin/python -m pip install doctest`.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcoGorellicommented, Oct 23, 2020

I think I have an idea, actually - does your doctest import something it’s not able to find?

The problem is that to detect whether you have the code quality tool you’re running installed or not, we do

    output = subprocess.run(
        [sys.executable, "-m", command, str(arg), *cmd_args],
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE,
        cwd=tmpdirname,
        env=env,
    )

    mutated = _get_mtimes(arg) != before

    output_code = output.returncode

    out = output.stdout.decode()
    err = output.stderr.decode()

    if "No module named" in err:
        raise ModuleNotFoundError(_get_command_not_found_msg(command))

However, this is buggy, because No module named might be returned by the code quality tool itself! So, we have a bug.

In the short-run, I’d recommend fixing your docstring so that everything you use in it was imported correctly. We’ll make a patch release for this at the weekend - @s-weigand had suggested a better way of checking if packages are installed, and I wish I’d followed his advice immediately now 😳

@all-contributors please add @ntaylor-nanigans for bug

0reactions
MarcoGorellicommented, Oct 23, 2020

closed in #365

@ntaylor-nanigans please try upgrading to version 0.3.4, I’d like to think this is fixed - if there are issues, please do let us know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

nbQA Documentation
nbqa mypy my_notebook.ipynb --ignore-missing-imports my_notebook.ipynb:cell_10:5: error: Argument "num1" to "add" has incompatible type ...
Read more >
Doctests fail on Python 3 · Issue #447 · asdf-format/asdf - GitHub
It seems that the 1.3.2 release was not done at the master branch: This is asdf/util.py in 1.3.2; still containing the lines from...
Read more >
python doctest is not running test when I'm running command ...
When I'm running below command from cmdline. python3.7 -m doctest -v src/helpers/string.py. This doesn't run any test.
Read more >
nbqa Changelog - PyUp.io
Fixed bug whereby local scripts / modules could not be run by ``nbQA`` due to incorrect ``ModuleNotFoundError``. 0.13.0. ~~~~~ ...
Read more >
doctest — Test interactive Python examples — Python 3.11.1 ...
The framework author typically wants to control doctest reporting options (perhaps, e.g., specified by command line options), but there's no way to pass...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found