mock import causes Problems on Ubuntu (missing requirement)
In a fresh 21.04 Ubuntu image there is a problem with mock being a missing dependency. mock should be long integrated into Python, available as unittest.mock
(see here https://pypi.org/project/mock/)
Installing mock via pip fixes the issue.
The question now is whether to put mock in requirements.txt or fix the import statements in the codebase?
Initial error message:
Traceback (most recent call last):
File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/__init__.py", line 268, in collectEnMAPBoxAlgorithms
import enmapboxgeoalgorithms.algorithms
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxgeoalgorithms/algorithms.py", line 6, in <module>
from enmapboxprocessing.algorithm.algorithms import algorithms
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/algorithms.py", line 3, in <module>
from enmapboxprocessing.algorithm.classificationperformancesimplealgorithm import \
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/classificationperformancesimplealgorithm.py", line 6, in <module>
from enmapboxprocessing.algorithm.classificationperformancestratifiedalgorithm import \
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/classificationperformancestratifiedalgorithm.py", line 12, in <module>
from enmapboxprocessing.algorithm.rasterizecategorizedvectoralgorithm import RasterizeCategorizedVectorAlgorithm
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/rasterizecategorizedvectoralgorithm.py", line 12, in <module>
from enmapboxprocessing.algorithm.rastermathalgorithm.rastermathalgorithm import RasterMathAlgorithm
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/rastermathalgorithm/rastermathalgorithm.py", line 10, in <module>
from mock import Mock
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'mock'
Comments (8)
-
-
- changed status to resolved
resolves
#773→ <<cset 309cac9cd57a>>
-
reporter Maybe we need to reopen this one and check for all mock occurrences, e.g. enmapboxplugin/enmapbox/externals/qps/testing.py is also affected.
E.g. in this case it is the statementimport mock
which has to be changed toimport unittest.mock
Assuming that mock == unittest.mock , but we should figure out quite fast if there are issues with that change, right? -
unittest.Mock works fine for me
-
Benjamin, please also use this in QPS.
-
-
assigned issue to
-
assigned issue to
-
- changed status to open
-
- changed status to resolved
resolves
#773→ <<cset 696292b0084f>>
- Log in to comment
I’ll change the imports to
from unittest.mock import Mock