Python API immediately raises an exception on import
Describe the bug
Importing the pxapi Python package into a project immediately raises a ModuleNotFoundError.
To Reproduce
Steps to reproduce the behavior:
- Optionally create a new Python virtual environment
- Install
pxapiwithpip install pxapi==0.6.0 - Start a new Python REPL
- Attempt to import
pxapi - Observe the raised
ModuleNotFoundErrorexception
Expected behavior
The pxapi package should be importable.
Screenshots
$ python
Python 3.9.13
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pxapi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/{{ REDACTED }}/.pyenv/versions/pixie-test/lib/python3.9/site-packages/pxapi/__init__.py", line 19, in <module>
from .data import Row
File "/Users/{{ REDACTED }}/.pyenv/versions/pixie-test/lib/python3.9/site-packages/pxapi/data.py", line 23, in <module>
from src.api.proto.vizierpb import vizierapi_pb2 as vpb
ModuleNotFoundError: No module named 'src.api.proto'
App information (please complete the following information):
- Pixie version: 0.6.0
- K8s cluster version: N/A
- Node Kernel version: N/A
- Browser version: N/A
Additional context
The Python API is sharing protobuf definition files with the Go API, and so the Python API source files attempt to import resources from beyond the top-level package directory. This issue is likely resolved by publishing a compliant package to PyPI, and either 1) including the required protobuf definition files in the resulting MANIFEST.in file, or 2) packaging the entire /api directory and excluding the Go API files in the resulting MANIFEST.in.
See Python's offical package publishing guide for more information on package requirements.
Thanks for letting us know.
I wasn't able to reproduce following your instructions, here's what I did.
pyenv virtualenv pxapi
pyenv activate pxapi
pip install pxapi==0.6.0
python -c "import pxapi"
Did you use a different pip install command or change something in the environment?
Apologies - I left out one very important detail. The issue only arises in projects importing pxapi that also have their own src/ directory housing their code (likely most projects, and all of mine). Because the pxapi imports from outside the /python directory are stored in their own relative src/ directory, the interpreter is unable to resolve the correct path.