pythonsetuptoolspypi

twine error with recent setuptools build but previous ones fine "InvalidDistribution: Metadata is missing required fields: Name, Version"


I'm trying to upload the python module I maintain to pypi (as I have done every few months for the last twelve years) but when I run twine check I get:

$ twine check dist/pi3d-2.55*
Checking dist/pi3d-2.55-py3-none-any.whl: ERROR    InvalidDistribution: Metadata is missing required fields: Name, Version.                                                                               
         Make sure the distribution includes the files where those fields are specified, and is using a supported Metadata-Version: 1.0, 1.1, 1.2, 2.0, 2.1,    
         2.2.

the module is https://github.com/tipam/pi3d/releases and if you look at the latest v2.55 that I'm trying to publish now compared with v2.54 published 2025/03/08 there are only tiny changes to a couple of files.

I hadn't upgraded setuptools, twine or pkginfo that I'm aware of (I've reinstalled --upgrade and various specific versions since first getting this error, of course)

The earlier builds in my pi3d/dist don't give the twine check error so I think it must be something to do with setuptools. I've tried all the suggestions I've found googling around the error message but the only thing I can find is that the wheel contains pi3d-2.55-py3-non-any/pi3d-2.55.dist-info/METADATA

Metadata-Version: 2.4
Name: pi3d
Version: 2.55
Summary: pi3d OpenGL 3D graphics library
Author: Tim Skillman, Paddy Gaunt, Tom Ritchford
Maintainer: Paddy Gaunt
License-Expression: MIT
Project-URL: Homepage, http://pi3d.github.com/html/index.html
Keywords: OpenGL,3D,r...

i.e. the Metadata-Version is 2.4 which isn't in the list given by the ERROR message! (Previous wheels have 2.2 and don't give the twine error)

Any clue what the actual problem is and how to solve it?

Paddy

PS EDIT if I change the content of the .whl file to set Metadata-Version: 2.2 twine passes it OK but I get an error from the server that it doesn't contain a WHEEL. There seems to be a file with that name at the location it gives.

$ twine upload dist/pi3d-2.55*.whl --verbose
Uploading distributions to https://upload.pypi.org/legacy/
INFO     dist/pi3d-2.55-py3-none-any.whl (307.5 KB)                                                                                                             
INFO     Querying keyring for password                                                                                                                          
Enter your API token: 
INFO     username: __token__                                                                                                                                    
INFO     password: <hidden>                                                                                                                                     
Uploading pi3d-2.55-py3-none-any.whl
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 319.9/319.9 kB • 00:02 • 193.1 kB/s
INFO     Response from https://upload.pypi.org/legacy/:                                                                                                         
         400 Invalid distribution file. WHEEL not found at pi3d-2.55.dist-info/WHEEL                                                                            
INFO     <html>                                                                                                                                                 
          <head>                                                                                                                                                
           <title>400 Invalid distribution file. WHEEL not found at pi3d-2.55.dist-info/WHEEL</title>                                                           
          </head>                                                                                                                                               
          <body>                                                                                                                                                
           <h1>400 Invalid distribution file. WHEEL not found at pi3d-2.55.dist-info/WHEEL</h1>                                                                 
           The server could not comply with the request since it is either malformed or otherwise incorrect.<br/><br/>                                          
         Invalid distribution file. WHEEL not found at pi3d-2.55.dist-info/WHEEL                                                                                
                                                                                                                                                                
                                                                                                                                                                
          </body>                                                                                                                                               
         </html>                                                                                                                                                
ERROR    HTTPError: 400 Bad Request from https://upload.pypi.org/legacy/                                                                                        
         Invalid distribution file. WHEEL not found at pi3d-2.55.dist-info/WHEEL

Solution

  • The error happens because your wheel is malformed: it has Metadata-Version: 2.4 (not recognized by older tools) and is missing the required .dist-info/WHEEL file. Fix it by upgrading your build tools and rebuilding cleanly:

    python -m pip install --upgrade setuptools wheel twine
    rm -rf dist build *.egg-info
    python -m build
    twine check dist/*
    twine upload dist/*
    

    This ensures the wheel contains correct metadata and the .dist-info/WHEEL file so PyPI accepts it.