I’ve been through the other answers, tried everything, and I’m still seeing this error.
My directory structure is:
package
├── test_sdtp_table_and_filter.py
<code>
├── __init__.py
├── app.py
├── pytest.ini
├── sdtp
│ ├── __init__.py
│ ├── sdtp_filter.py
│ ├── sdtp_table.py
│ └── sdtp_utils.py
├── sdtp_server
│ ├── __init__.py
│ ├── sdtp_server.py
│ └── table_server.py
├── setup.cfg
├── setup.py
└── tests
├── __init__.py
├── conftest.py
├── pytest.ini
├── test_sdtp_filter.py
├── test_sdtp_server.py
├── test_sdtp_table.py
├── test_sdtp_table_and_filter.py
├── test_sdtp_utils.py
└── test_table_server.py
</code>
├── __init__.py
├── app.py
├── pytest.ini
├── sdtp
│ ├── __init__.py
│ ├── sdtp_filter.py
│ ├── sdtp_table.py
│ └── sdtp_utils.py
├── sdtp_server
│ ├── __init__.py
│ ├── sdtp_server.py
│ └── table_server.py
├── setup.cfg
├── setup.py
└── tests
├── __init__.py
├── conftest.py
├── pytest.ini
├── test_sdtp_filter.py
├── test_sdtp_server.py
├── test_sdtp_table.py
├── test_sdtp_table_and_filter.py
├── test_sdtp_utils.py
└── test_table_server.py
pytest.ini is
pythonpath = /workspaces/sdtp
<code>[pytest]
pythonpath = /workspaces/sdtp
</code>
[pytest]
pythonpath = /workspaces/sdtp
conftest.py is:
from os.path import dirname as d
from os.path import abspath, join
root_dir = d(d(abspath(__file__)))
sys.path.append(root_dir)
<code>#
# conftest.py
import sys
from os.path import dirname as d
from os.path import abspath, join
root_dir = d(d(abspath(__file__)))
sys.path.append(root_dir)
</code>
#
# conftest.py
import sys
from os.path import dirname as d
from os.path import abspath, join
root_dir = d(d(abspath(__file__)))
sys.path.append(root_dir)
The root level init.py is:
<code>from sdtp.sdtp_utils import InvalidDataException
from sdtp.sdtp_utils import SDTP_BOOLEAN, SDTP_DATE, SDTP_DATETIME, SDTP_NUMBER, SDTP_PYTHON_TYPES, SDTP_SCHEMA_TYPES, SDTP_STRING, SDTP_TIME_OF_DAY
from sdtp.sdtp_utils import type_check, check_sdtp_type_of_list, jsonifiable_value, jsonifiable_row, jsonifiable_rows, jsonifiable_column, convert_to_type, convert_list_to_type, convert_row_to_type_list, convert_rows_to_type_list, convert_dict_to_type
from sdtp.sdtp_filter import SDTP_FILTER_OPERATORS, SDTP_FILTER_FIELDS, check_valid_spec, SDTPFilter
from sdtp.sdtp_table import SDTPTable, SDTPFixedTable, DataFrameTable, RowTable, RemoteCSVTable, RemoteSDTPTable
from sdtp_server.table_server import Table, TableServer, TableNotAuthorizedException, TableNotAuthorizedException, ColumnNotFoundException
from sdtp_server.table_server import build_table_spec
from sdtp_server.sdtp_server import sdtp_server_blueprint
<code>from sdtp.sdtp_utils import InvalidDataException
from sdtp.sdtp_utils import SDTP_BOOLEAN, SDTP_DATE, SDTP_DATETIME, SDTP_NUMBER, SDTP_PYTHON_TYPES, SDTP_SCHEMA_TYPES, SDTP_STRING, SDTP_TIME_OF_DAY
from sdtp.sdtp_utils import type_check, check_sdtp_type_of_list, jsonifiable_value, jsonifiable_row, jsonifiable_rows, jsonifiable_column, convert_to_type, convert_list_to_type, convert_row_to_type_list, convert_rows_to_type_list, convert_dict_to_type
from sdtp.sdtp_filter import SDTP_FILTER_OPERATORS, SDTP_FILTER_FIELDS, check_valid_spec, SDTPFilter
from sdtp.sdtp_table import SDTPTable, SDTPFixedTable, DataFrameTable, RowTable, RemoteCSVTable, RemoteSDTPTable
from sdtp_server.table_server import Table, TableServer, TableNotAuthorizedException, TableNotAuthorizedException, ColumnNotFoundException
from sdtp_server.table_server import build_table_spec
from sdtp_server.sdtp_server import sdtp_server_blueprint
</code>
from sdtp.sdtp_utils import InvalidDataException
from sdtp.sdtp_utils import SDTP_BOOLEAN, SDTP_DATE, SDTP_DATETIME, SDTP_NUMBER, SDTP_PYTHON_TYPES, SDTP_SCHEMA_TYPES, SDTP_STRING, SDTP_TIME_OF_DAY
from sdtp.sdtp_utils import type_check, check_sdtp_type_of_list, jsonifiable_value, jsonifiable_row, jsonifiable_rows, jsonifiable_column, convert_to_type, convert_list_to_type, convert_row_to_type_list, convert_rows_to_type_list, convert_dict_to_type
from sdtp.sdtp_filter import SDTP_FILTER_OPERATORS, SDTP_FILTER_FIELDS, check_valid_spec, SDTPFilter
from sdtp.sdtp_table import SDTPTable, SDTPFixedTable, DataFrameTable, RowTable, RemoteCSVTable, RemoteSDTPTable
from sdtp_server.table_server import Table, TableServer, TableNotAuthorizedException, TableNotAuthorizedException, ColumnNotFoundException
from sdtp_server.table_server import build_table_spec
from sdtp_server.sdtp_server import sdtp_server_blueprint
The error is:
<code>vscode ➜ /workspaces/sdtp (main) $ pytest -vvv tests/test_sdtp_utils.py
ImportError while loading conftest '/workspaces/sdtp/tests/conftest.py'.
__init__.py:9: in <module>
from sdtp.sdtp_utils import InvalidDataException
E ModuleNotFoundError: No module named 'sdtp.sdtp_utils'
<code>vscode ➜ /workspaces/sdtp (main) $ pytest -vvv tests/test_sdtp_utils.py
ImportError while loading conftest '/workspaces/sdtp/tests/conftest.py'.
__init__.py:9: in <module>
from sdtp.sdtp_utils import InvalidDataException
E ModuleNotFoundError: No module named 'sdtp.sdtp_utils'
</code>
vscode ➜ /workspaces/sdtp (main) $ pytest -vvv tests/test_sdtp_utils.py
ImportError while loading conftest '/workspaces/sdtp/tests/conftest.py'.
__init__.py:9: in <module>
from sdtp.sdtp_utils import InvalidDataException
E ModuleNotFoundError: No module named 'sdtp.sdtp_utils'
Further, I added:
<code>import sys
print(sys.path)
</code>
import sys
print(sys.path)
to the init.py file (just before the ImportError
) and got this result:
<code>['/workspaces', '/workspaces/sdtp', '/opt/conda/bin', '/opt/conda/lib/python311.zip', '/opt/conda/lib/python3.11', '/opt/conda/lib/python3.11/lib-dynload', '/opt/conda/lib/python3.11/site-packages']
<code>['/workspaces', '/workspaces/sdtp', '/opt/conda/bin', '/opt/conda/lib/python311.zip', '/opt/conda/lib/python3.11', '/opt/conda/lib/python3.11/lib-dynload', '/opt/conda/lib/python3.11/site-packages']
</code>
['/workspaces', '/workspaces/sdtp', '/opt/conda/bin', '/opt/conda/lib/python311.zip', '/opt/conda/lib/python3.11', '/opt/conda/lib/python3.11/lib-dynload', '/opt/conda/lib/python3.11/site-packages']
the imports are in /workspaces/sdtp/sdtp, and that has an init.py file, so it’s (a) on the path; and (b) a module, and (c) it’s found just before the import error
Moreover
<code>$ python
> import __init__
> SDTP_BOOLEAN
'boolean'
</code>
$ python
> import __init__
> SDTP_BOOLEAN
'boolean'
works just fine, so when Python is run directly there is no ImportError.
I added conftest.py and pytest.ini after reading the answers here: ModuleNotFoundError with pytest
Can anyone tell me what’s going on?
I tried:
- Running python native (worked fine)
- Printing sys.path (got what I expected)
- Adding conftest.py and pytest.ini (no effect)