rustworkx icon indicating copy to clipboard operation
rustworkx copied to clipboard

All tests fail: ModuleNotFoundError: No module named 'rustworkx.rustworkx'

Open yurivict opened this issue 3 years ago • 5 comments

Information

  • retworkx version: e9edfdc
  • Python version: 3.9
  • Rust version: 1.62.1
  • Operating system: FreeBSD 13.1

What is the current behavior?

==================================================================================== test session starts =====================================================================================
platform freebsd13 -- Python 3.9.13, pytest-7.1.2, pluggy-1.0.0 -- /usr/local/bin/python3.9
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/disk-samsung/freebsd-ports/math/py-retworkx/work-py39/rustworkx-0.11.0-51-ge9edfdc/.hypothesis/examples')
rootdir: /disk-samsung/freebsd-ports/math/py-retworkx/work-py39/rustworkx-0.11.0-51-ge9edfdc
plugins: forked-1.4.0, hypothesis-6.53.0, xdist-2.5.0, cov-2.9.0, typeguard-2.13.3, mock-1.10.4, asyncio-0.18.3, trio-0.7.0, flaky-3.7.0
asyncio: mode=legacy
collecting 0 items / 47 errors                                                                                                                                                               ^collecting 0 items / 56 errors                                                                                                                                                               ^collecting 0 items / 62 errors                                                                                                                                                               ^collected 0 items / 65 errors                                                                                                                                                                
^C
=========================================================================================== ERRORS ===========================================================================================
____________________________________________________________ ERROR collecting tests/retworkx_backwards_compat/test_converters.py _____________________________________________________________
ImportError while importing test module '/disk-samsung/freebsd-ports/math/py-retworkx/work-py39/rustworkx-0.11.0-51-ge9edfdc/tests/retworkx_backwards_compat/test_converters.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/retworkx_backwards_compat/test_converters.py:14: in <module>
    import retworkx
retworkx/__init__.py:14: in <module>
    from rustworkx import *  # noqa
rustworkx/__init__.py:13: in <module>
    from .rustworkx import *
E   ModuleNotFoundError: No module named 'rustworkx.rustworkx'
________________________________________________________ ERROR collecting tests/retworkx_backwards_compat/test_custom_return_types.py ________________________________________________________
ImportError while importing test module '/disk-samsung/freebsd-ports/math/py-retworkx/work-py39/rustworkx-0.11.0-51-ge9edfdc/tests/retworkx_backwards_compat/test_custom_return_types.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/retworkx_backwards_compat/test_custom_return_types.py:17: in <module>
    import retworkx
retworkx/__init__.py:14: in <module>
    from rustworkx import *  # noqa
rustworkx/__init__.py:13: in <module>
    from .rustworkx import *
E   ModuleNotFoundError: No module named 'rustworkx.rustworkx'
_____________________________________________________________ ERROR collecting tests/retworkx_backwards_compat/test_dispatch.py ______________________________________________________________
ImportError while importing test module '/disk-samsung/freebsd-ports/math/py-retworkx/work-py39/rustworkx-0.11.0-51-ge9edfdc/tests/retworkx_backwards_compat/test_dispatch.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/retworkx_backwards_compat/test_dispatch.py:14: in <module>
    import retworkx
retworkx/__init__.py:14: in <module>
    from rustworkx import *  # noqa
rustworkx/__init__.py:13: in <module>
    from .rustworkx import *
E   ModuleNotFoundError: No module named 'rustworkx.rustworkx'
______________________________________________________________ ERROR collecting tests/retworkx_backwards_compat/test_graphml.py ______________________________________________________________

yurivict avatar Aug 08 '22 17:08 yurivict

Where are you running from? A common trap for python is that if there is a directory with an __init__.py file in your current working directory Python will use that directory for the package instead of an installed copy on import (see the last paragraph in: https://github.com/Qiskit/rustworkx#building-from-source ). The easiest way around this is to just change directory so python uses your installed package. Alternatively you can install the lib file inplace with python setup.py build_rust --release --inplace to build the extension file in your local repo directly so that even if Python imports rustworkx from your local path it has the lib file available.

mtreinish avatar Aug 08 '22 17:08 mtreinish

It runs from this directory which has no __init__.py:

$ ls /disk-samsung/freebsd-ports/math/py-rustworkx/work-py39/rustworkx-0.11.0-51-ge9edfdc
CITATION.bib       Cargo.lock         MANIFEST.in        cargo-crates       pyproject.toml     rustfmt.toml       rustworkx.egg-info target             tox.ini
CODE_OF_CONDUCT.md Cargo.toml         README.md          constraints.txt    releasenotes       rustworkx          setup.py           tests
CONTRIBUTING.md    LICENSE            build              docs               retworkx           rustworkx-core     src                tools

yurivict avatar Aug 08 '22 17:08 yurivict

Running from the tests subdirectory has the same problem.

yurivict avatar Aug 08 '22 17:08 yurivict

I meant rustworkx/__init__.py which is looks like is the case here. If python detects a local directory that looks like a python package (meaning it has an __init__.py in it) python defaults to using that directory for imports instead of an installed package. So in this case when you run pytest python is importing rustworkx from ./rustworkx instead of /usr/local/lib/python3.9/site-packages/rustworkx

mtreinish avatar Aug 08 '22 17:08 mtreinish

From the upper directory tests now fail this way:

==================================================================================== test session starts =====================================================================================
platform freebsd13 -- Python 3.9.13, pytest-7.1.2, pluggy-1.0.0 -- /usr/local/bin/python3.9
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/usr/home/yuri/.hypothesis/examples')
rootdir: /usr/home/yuri
plugins: forked-1.4.0, hypothesis-6.53.0, xdist-2.5.0, cov-2.9.0, typeguard-2.13.3, mock-1.10.4, asyncio-0.18.3, trio-0.7.0, flaky-3.7.0
asyncio: mode=legacy
collecting ... Failed to import pybind11_tests from pytest:
  ModuleNotFoundError: No module named 'pybind11_tests'
collected 0 items / 1 error                                                                                                                                                                  

=========================================================================================== ERRORS ===========================================================================================
_______________________________________________________________________________ ERROR collecting test session ________________________________________________________________________________
disk-samsung/fractalcores/fcdnnV3/external/libonnxruntime/include/third_party/onnx/third_party/pybind11/tests/conftest.py:234: in _test_import_pybind11
    import pybind11_tests  # noqa: F401 imported but unused
E   ModuleNotFoundError: No module named 'pybind11_tests'

During handling of the above exception, another exception occurred:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
    ???
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:680: in _load_unlocked
    ???
/usr/local/lib/python3.9/site-packages/_pytest/assertion/rewrite.py:168: in exec_module
    exec(co, module.__dict__)
disk-samsung/fractalcores/fcdnnV3/external/libonnxruntime/include/third_party/onnx/third_party/pybind11/tests/conftest.py:241: in <module>
    _test_import_pybind11()
disk-samsung/fractalcores/fcdnnV3/external/libonnxruntime/include/third_party/onnx/third_party/pybind11/tests/conftest.py:238: in _test_import_pybind11
    sys.exit(1)
E   SystemExit: 1
====================================================================================== warnings summary ======================================================================================
../../local/lib/python3.9/site-packages/pytest_asyncio/plugin.py:191
  /usr/local/lib/python3.9/site-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================================== 1 warning, 1 error in 148.93s (0:02:28) ===========================================================================

pybind11_tests isn't listed in setup.py as a requirement. It's unclear if any tests ran successfully.

yurivict avatar Aug 08 '22 17:08 yurivict

From the upper directory tests now fail this way:

==================================================================================== test session starts =====================================================================================
platform freebsd13 -- Python 3.9.13, pytest-7.1.2, pluggy-1.0.0 -- /usr/local/bin/python3.9
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/usr/home/yuri/.hypothesis/examples')
rootdir: /usr/home/yuri
plugins: forked-1.4.0, hypothesis-6.53.0, xdist-2.5.0, cov-2.9.0, typeguard-2.13.3, mock-1.10.4, asyncio-0.18.3, trio-0.7.0, flaky-3.7.0
asyncio: mode=legacy
collecting ... Failed to import pybind11_tests from pytest:
  ModuleNotFoundError: No module named 'pybind11_tests'
collected 0 items / 1 error                                                                                                                                                                  

=========================================================================================== ERRORS ===========================================================================================
_______________________________________________________________________________ ERROR collecting test session ________________________________________________________________________________
disk-samsung/fractalcores/fcdnnV3/external/libonnxruntime/include/third_party/onnx/third_party/pybind11/tests/conftest.py:234: in _test_import_pybind11
    import pybind11_tests  # noqa: F401 imported but unused
E   ModuleNotFoundError: No module named 'pybind11_tests'

During handling of the above exception, another exception occurred:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
    ???
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:680: in _load_unlocked
    ???
/usr/local/lib/python3.9/site-packages/_pytest/assertion/rewrite.py:168: in exec_module
    exec(co, module.__dict__)
disk-samsung/fractalcores/fcdnnV3/external/libonnxruntime/include/third_party/onnx/third_party/pybind11/tests/conftest.py:241: in <module>
    _test_import_pybind11()
disk-samsung/fractalcores/fcdnnV3/external/libonnxruntime/include/third_party/onnx/third_party/pybind11/tests/conftest.py:238: in _test_import_pybind11
    sys.exit(1)
E   SystemExit: 1
====================================================================================== warnings summary ======================================================================================
../../local/lib/python3.9/site-packages/pytest_asyncio/plugin.py:191
  /usr/local/lib/python3.9/site-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================================== 1 warning, 1 error in 148.93s (0:02:28) ===========================================================================

pybind11_tests isn't listed in setup.py as a requirement. It's unclear if any tests ran successfully.

We do not require pybind or pytest. If you look carefully, you are running tests for another package, onnx.

I am going to close this issue because it is very much likely to that you are running into the documented pitfall that Matthew commented earlier (https://github.com/Qiskit/rustworkx#building-from-source).

Lastly, for reproducibility and support purposes, run our tests with tox as documented in CONTRIBUTING.md:

tox -epy

IvanIsCoding avatar Aug 15 '22 22:08 IvanIsCoding