I was following a tutorial on how to build a Python package, and after installing the package locally using pip install . In the project directory.
The next was to python -m build in the project directory, but get
No module named build.__main__; 'build' is a package and cannot be directly executed
I do have a build folder , but not __main__.py file though.
The repo of the project is here
Update: as of 2024-11-03, the latest build version 1.2.2.post1 works fine
Apparently, a new version of build 0.10.0 was released that no longer works like this or has a bug.
For a quick fix simply:
pip install 'build<0.10.0'
Then everything should work like in your tutorial.
By the way, these links below are my favorite tutorial about how to make a pip installable python package.
One thing you should check is PYTHONPATH. If it matches some other "build" then you can hit this issue.
You can see where it thinks the module should be imported from using the code below. In my case I work for a large company with lots of different repo's etc... It was picking up an internal "build" directory for something else...
import build
print(build.__path__)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With