DEV Community

Sean Atukorala
Sean Atukorala

Posted on

[Solved] Pytest Error: ImportError: Error importing plugin '': No module named ...


Running into the following error when trying to run a Pytest test suite in a Python application via the pytest command:

 File "/usr/lib/python2.7/dist-packages/_pytest/", line 94, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/lib/python2.7/dist-packages/pluggy/", line 81, in get_result
    _reraise(*ex)  # noqa
  File "/usr/lib/python2.7/dist-packages/pluggy/", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/", line 739, in pytest_cmdline_parse
  File "/usr/lib/python2.7/dist-packages/_pytest/config/", line 947, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/", line 889, in _preparse
  File "/usr/lib/python2.7/dist-packages/_pytest/config/", line 499, in consider_preparse
  File "/usr/lib/python2.7/dist-packages/_pytest/config/", line 524, in consider_pluginarg
    self.import_plugin(arg, consider_entry_points=True)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/", line 574, in import_plugin
    six.reraise(ImportError, new_exc, tb)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/", line 565, in import_plugin
ImportError: Error importing plugin "sklearn.tests.random_seed": No module named sklearn.tests.random_seed
Enter fullscreen mode Exit fullscreen mode


There are a number of potential causes for this issue, the most likely being that the PYTHONPATH environment variable not being defined in your ~/.profile file. There are two potential solutions you can try here:

  1. Define the PYTHONPATH environment variable by running the command export PYTHONPATH=<your_user_defined_module_path_here>. Then retry running pytest
  2. Add the prefix python -m before the usual pytest command like so: python -m pytest


Well this is the end of the article, if you have any questions or concerns please feel free to post a comment in this article and I will get back to you if I find the time.

I hope you found this article helpful. Thanks so much for reading my article! Feel free to follow me on Twitter and GitHub, connect with me on LinkedIn and subscribe to my YouTube channel.

Top comments (0)