Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

" No module named build.__main__; 'build' is a package and cannot be directly executed " when doing 'python -m build'

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

like image 670
akashKP Avatar asked Dec 18 '25 12:12

akashKP


2 Answers

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.

  • https://packaging.python.org/guides/distributing-packages-using-setuptools/
  • https://github.com/pypa/sampleproject
like image 105
bue Avatar answered Dec 20 '25 17:12

bue


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__)
like image 32
TheDude Avatar answered Dec 20 '25 18:12

TheDude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!