"python3 -m build" [Errno 2] No such file or directory: 'Example/interfaces/example.proto'

3 hours ago 3
ARTICLE AD BOX

Python version is 3.9.21. OS is Rocky Linux 9.

Our group has little experience with python. We were given 3rd party python code with no documentation. I started learning basic concepts: modules, packages, libraries, projects, .whl, .venv, .toml, etc. Per README in an external dependency folder, I used the python3 -m build command to create a .whl file, so I tried using it on their example project. But I get this error:

python3 -m build error: [Errno 2] No such file or directory: 'Example/interfaces/example.proto' ERROR Backend subprocess exited when trying to invoke build_wheel

Here are the contents of the src folder:

(.venv) [root@dd-rocky9-us0cnd23904yl-adbf20 src]# ls -aR .: . .. Example pyproject.toml ./Example: . .. __init__.py __main__.py example_pb2.py interfaces ./Example/interfaces: . .. example.proto

SO's AI Assist gave me advice so I added a MANIFEST.in file into the src folder:
recursive-include Example/interfaces *.proto
I also tried this line with ...src/Example/...

AI Assist also suggested editing the pyproject.toml file. Original text is:

[build-system] requires = [ 'setuptools >= 41.9.0', 'setuptools-protobuf', 'wheel' ] build-backend = 'setuptools.build_meta' [tool.setuptools-protobuf] proto_path = 'src/Example/interfaces' protobufs = [ 'example.proto', ] [project] name = 'Example' version = '0.1.0' ...

I added:

[tool.setuptools.package-data] "Example" = ["interfaces/*.proto"] [tool.setuptools] include-package-data = true

Always get the same error (sometimes with src/Example depending on what I tried).

Looks like a path issue. With further searching at level above the ./src/ folder (where the .venv folder is located), I added a .env file with contents

PYTHONPATH=/workspaces/pyproj/src/ /workspaces/pyproj:${PYTHONPATH}

Finally, I tried to enter at command line:
export PYTHONPATH=/workspaces/pyproj/src/

Read Entire Article