How to fix Python tox ImportError: cannot import name 'cmdline' from 'tox'

Problem:

When trying to run your unit tests using tox you see the following error message:

tox_traceback.txt
Traceback (most recent call last):
    File "/home/uli/.local/bin/tox", line 5, in <module>
        from tox import cmdline
ImportError: cannot import name 'cmdline' from 'tox' (/usr/local/lib/python3.10/dist-packages/tox/__init__.py)

Solution

You’re using an older version of tox as an executable. To find out which executable you’re using, check this line of the error message:

tox_exec_path.txt
File "/home/uli/.local/bin/tox", line 5, in <module>

In our case, the executable is

example.txt
/home/uli/.local/bin/tox

Delete that file!

After that, tox should work fine. If not, update tox using

upgrade_tox.sh
pip install -U tox

 


Check out similar posts by category: Python