pythonpython-unittest

Python 3.11: No module named "unittest.mock"


I have tried to run a program using pytorch. It stopped with the error 'No module named "unittest.mock"' Then I wrote a minimal python program:

import unittest.mock
if __name__ == '__main__':
    print("Hello world")

The same error. Documentation in https://docs.python.org/3.11/library/unittest.mock.html#module-unittest.mock. This module should be builtin since 3.3

Environment: python 3.11.2, Debian-Bookworm

Running in Debian-Bullseye with python 3.9: the same problem


Solution

  • The program "import unittest; print(unittest)" shows the location of an (unexpected) self written module "unittest". That module has blocked the builtin module.

    Thanks to wjandrea!