How to overwrite pypi package when doing upload from command line?
Asked Answered
F

3

45

I want to automate the upload process bug in some cases the python setup.py upload fails because pypi server already have the save version uploaded.

How can I force it to upload, from the script (i know I can remove the old variant using the web interface).

Fiddlewood answered 11/1, 2014 at 16:11 Comment(5)
I had the same problem but could not find a way to do it with current pypi and setuptools.Nicholas
Especially with the existence of the test pypi server, this seems ridiculous. Even if you remove that existing version from the server you can't re-upload that version, saying "this filename has previously been used, you should use a different version. This should at least be possible on the test server. Bad form, pypi.Axel
The test server, meant to learn the real thing, should in my opinion behave like the real thing. And any change should force a new version subnumber. Because if you took the trouble to upload an improvement, why not grant the user the privilige to download it? Allowing deleted versions to be overwritten could be a potential source of chaos. Who will tell what is a significant change and what not.Protochordate
I wish I had more than one upvote to give @obsoleteaccount. Even if your change is "just a bug fix," overwriting existing or deleted versions opens the door for someone to upload "just a breaking change." Think of it as another case of "explicit is better than implicit" if that helps.Dumbarton
snap application packages have a revision number along with their version number. I often update my snapstore application with the same version (when I have a extremely small change), and it adds next revision to let the users know a update is published. Disappointed to see PyPI doesn't have something like this. Even manually deleting the version won't help.Wawro
H
52

A late answer, but: it seems everybody agrees you can't overwrite existing pypi uploads, or re-upload a fixed version after you delete a broken version. However, it seems actually possible and officially supported: "build numbers" are a feature that nobody has ever used or remembers they exist, but that seems to work, at least for me.

The trick is to rename the files in the following pattern:

mypackage-0.31.0-py2.py3-none-any.whl
mypackage-0.31.0-1-py2.py3-none-any.whl
mypackage-0.31.0-2-py2.py3-none-any.whl

The "-1" or "-2" are build numbers. If pip finds all these files for the same release, it will pick the one with the highest build number. It also seems to work if it finds only a single file with a non-zero build number, so you can use that after you deleted the original.

(This is very quickly mentioned in the documentation at https://www.python.org/dev/peps/pep-0427/#file-name-convention but I wouldn't have guessed its use without Daniel Holth pointing it out to me. Thanks Daniel!)

I have no idea why the internet contains so many people convinced it can't be done. I myself only learned about it yesterday and thought I should try to pass on that information.

Insert here the usual warning about not to abuse that feature. A typical example for when I think you should use this is after one of the wheels was badly built and you need to replace it with a correctly-built wheel from the same sources

Hatshepsut answered 17/9, 2020 at 18:28 Comment(4)
When I did this trick, I renamed the .whl and .tar.gz files as described and it worked but it showed up on pypi with a build number not of 1 but of post1. So I renamed to 1.1.0-1 but the version on pypi was 1.1.0.post1. Other than that this works.Exegetic
I tried to use the same trick on the source package, to update the source code in a way that doesn't change any of the wheels. That doesn't work. Looks like there is no solution for that short of rebuilding all the wheels and making a full release.Hatshepsut
This worked nicely. In order to upload the new tar.gz archive, you need to remove the old one first. Otherwise, you'll get 400 Only one sdist may be uploaded per release.Successive
Unfortunately, it doesn't appear this can be used to update project descriptions. I tried it on the test server and the description is the same even after deleting the original wheel.Rectus
D
8

Here's an actual answer, not just me adding more pontification in the comments. Found this thread:

https://www.reddit.com/r/Python/comments/35xr2q/howto_overwrite_package_when_reupload_to_pypi/

That refers to this:

http://comments.gmane.org/gmane.comp.python.distutils.devel/22739

Saying it can't be done.

Also note the comment in the reddit thread about reading semver.org and incrementing the micro version for patches.

Dumbarton answered 18/9, 2015 at 14:42 Comment(0)
T
0

You can overwrite the version with this command

twine upload --skip-existing dist/*

This will skip existing distributions and upload newer ones.

Tuscarora answered 20/12, 2023 at 19:17 Comment(1)
All this does is ignore files that already exist in the remote, it does not overwrite anything like the OP was asking.Rome

© 2022 - 2025 — McMap. All rights reserved.