splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

ImportWarning: _SixMetaPathImporter.find_spec() not found starting from python3.10

Open VmirGerts opened this issue 3 years ago • 3 comments

Describe the bug Starting from python version "3.10", running pytest -W error with a test file which imports splunklib produces following ImportWarning (interpreted as an error due to the "-W error" flag):

E ImportWarning: _SixMetaPathImporter.find_spec() not found; falling back to find_module() (see full log below)

To Reproduce Note: the steps 1 and 3 are only necessary because Ubuntu20.04 does not provide python3.10 out of the box.

  1. If python3.10 is not installed:
add-apt-repository ppa:deadsnakes/ppa
apt install -y python3.10 python3.10-dev python3.10-venv python3.10-distutils
  1. Create and activate python3.10 environment:
virtualenv venv -p /usr/bin/python3.10
. venv/bin/activate
  1. Upgrade pip
curl -sS https://bootstrap.pypa.io/get-pip.py | python
  1. Install required packages
pip install pytest splunk-sdk
  1. Create following test file 'test_splunk_sdk.py'
import splunklib

def test_splunklib():
    pass
  1. Run pytest with "-W error"
pytest test_splunk_sdk.py -W error

Expected behavior No ImportWarning

Logs or Screenshots Complete log:

$ pytest -W error test_splunk_sdk.py 
================================================================================= test session starts ==================================================================================
platform linux -- Python 3.10.12, pytest-7.4.0, pluggy-1.2.0
rootdir: /home/username/test_splunk_sdk
collected 0 items / 1 error                                                                                                                                                            

======================================================================================== ERRORS ========================================================================================
_________________________________________________________________________ ERROR collecting test_splunk_sdk.py __________________________________________________________________________
<frozen importlib._bootstrap>:939: in _find_spec
    ???
E   AttributeError: '_SixMetaPathImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:
venv/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
venv/lib/python3.10/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
venv/lib/python3.10/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
venv/lib/python3.10/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
venv/lib/python3.10/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
venv/lib/python3.10/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
venv/lib/python3.10/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
venv/lib/python3.10/site-packages/_pytest/pathlib.py:565: in import_path
    importlib.import_module(module_name)
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
test_splunk_sdk.py:2: in <module>
    import splunklib
venv/lib/python3.10/site-packages/splunklib/__init__.py:18: in <module>
    from splunklib.six.moves import map
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1002: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:941: in _find_spec
    ???
<frozen importlib._bootstrap>:914: in _find_spec_legacy
    ???
E   ImportWarning: _SixMetaPathImporter.find_spec() not found; falling back to find_module()
=============================================================================== short test summary info ================================================================================
ERROR test_splunk_sdk.py - ImportWarning: _SixMetaPathImporter.find_spec() not found; falling back to find_module()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================================================================== 1 error in 0.12s ===================================================================================

SDK (please complete the following information):

  • splunk-sdk version: 1.7.3
  • tested on Python3.10, Python3.11
  • pytest version: 7.4.0
  • OS: Ubuntu 20.04

Fix suggestion

Update the six.py with the newer version from the official repo: https://github.com/benjaminp/six/blob/master/six.py The newer version provides the find_spec() function.

VmirGerts avatar Jul 19 '23 14:07 VmirGerts

Hi @VmirGerts, this quarter we are planning on a new beta release for the Python SDK with updated support for Python 3.9 and hope to resolve this issue as we are removing six.py dependency. Please watch for updates here.

ashah-splunk avatar Oct 26 '23 06:10 ashah-splunk

Hi @VmirGerts Sorry for the delay, we have published a new version of Python SDK v2.0.0 with Python v3.7+ support. Request you to use the latest SDK and let us know if the issue is resolved. Thanks

ashah-splunk avatar Mar 21 '24 12:03 ashah-splunk

Hi @ashah-splunk , thank you for the update! I can confirm that the issue is fixed now.

Btw, just for the purpose of completeness: I realized that one could just run python -Werror -c "import splunklib" to reproduce the error. So creating a test file was not necessary.

VmirGerts avatar Mar 26 '24 09:03 VmirGerts