How to upload new versions of project to PyPI with twine?
Asked Answered
D

9

77

I've uploaded my Python package to PyPI. But now I made new version of my package and need to upload it. I tried to make same progress which I did when upload the package first time but I got the error below:

HTTPError: 400 Client Error: File already exists. See https://pypi.org/help/#file-name-reuse for url: https://upload.pypi.org/legacy

Now, how to upload new version without any error?!

Dormancy answered 25/8, 2018 at 10:26 Comment(1)
I needed to remove the extant ./dist to upload my new versionFlamboyant
T
145

PyPI does not allow for the reuse of distribution filenames (project name + version number + distribution type).

This ensures that a given distribution for a given release for a given project will always resolve to the same file, and cannot be surreptitiously changed one day by the projects maintainer or a malicious party (it can only be removed).

You will need to change the version number to one that you haven't previously uploaded to PyPI.

You didn't mention how you're uploading the distribution, but if you're using twine, it's also possible you're attempting to re-upload a previously uploaded distribution. To resolve this, you can do:

$ twine upload --skip-existing dist/*
Tildi answered 1/9, 2018 at 18:20 Comment(1)
Oh I see, that I need to remove old dist in my folder.... Then there is not such an error message.Lawtun
C
19

Can get that error for following reasons:

  • Didn't change your version in setup.py
  • didn't remove your previous dist file

Solution:

  • Change the version number in setup.py.
  • Run setup file again. python setup.py bdist_wheel.
  • Upload only that dist file or run twine (if using). twine upload --skip-existing dist/*

As mentioned by @dustin, dist file of same name cannot be uploaded again.

Couturier answered 25/5, 2019 at 7:59 Comment(0)
P
4

You need to change the version number.

Popup answered 25/8, 2018 at 10:34 Comment(0)
S
4

The error seems to stem from the command:

twine upload --repository-url https://test.pypi.org/legacy/ dist/*
reusing the previous package version.

To fix this, try this:

twine upload --skip-existing --repository-url https://test.pypi.org/legacy/ 
dist/*
Slobbery answered 4/8, 2020 at 15:50 Comment(1)
This is the correct answer (as also in other answers). Updating version number doesn't help if you have previous version built in same directory as new, since twine tries to upload all the versions found in that (dist) folder.Antidote
L
3

Make sure your dist directory is empty before running

python setup.py sdist
Laurent answered 22/7, 2020 at 16:34 Comment(0)
A
2

Another way that nobody mentioned is to provide an explicit filename:

twine upload --repository testpypi --skip-existing dist/myProject-0.1.9-py3-none-any.whl

This has advantages compared to the other proposed solutions, and precisely:

  • while updating version number is a requirement for twine to upload the package, this doesn't prevent the program to upload everything that is the dist folder, included previously uploaded versions. It's ok if you move out the old versions, but I am not sure about possible implications.
  • using --skip-existing option solves the above problem, but all files are still processed, so it takes time.

I am sure there are more efficient solutions, but this is simple enough for me.

Antidote answered 26/7, 2021 at 10:40 Comment(0)
R
0

if you have an old dist directory, delete it before running

python setup.py bdist_wheel

reason: It contains old version files, which causes problems while uploading to PyPI using twine

Rozellarozelle answered 24/2, 2023 at 14:54 Comment(0)
C
0

I got the same error below:

HTTPError: 400 Bad Request from https://test.pypi.org/legacy/ File already exists. See https://test.pypi.org/help/#file-name-reuse for more information.

When I tried to upload a package to TestPyPI with the command below:

twine upload --repository testpypi dist/*

So, I changed version from "0.0.1" to "0.0.2" or name from "example_package_superkai" to "example_package_hyperkai" in pyproject.toml as shown below, then I removed dist folder:

# "pyproject.toml"

...
[project]
...
# version = "0.0.1"
version = "0.0.2"
...

Or:

# "pyproject.toml"

...
[project]
# name = "example_package_superkai"
name = "example_package_hyperkai"
...

Then, I ran the command below:

python -m build

Finally, I could upload a package to TestPyPI with the command below:

twine upload --repository testpypi dist/*
Cyn answered 6/6, 2023 at 12:12 Comment(0)
L
-1

just delete the dist file if you want to reuse the same version and run below commands py -m build py -m twine upload --repository testpypi dist/* If your are using testpypi repo

It is working for me .

Liaoyang answered 28/9, 2023 at 8:0 Comment(1)
When you can see that there are already multiple answers for a simple question, please read them before adding another one, and carefully consider whether you add any new information.Scilicet

© 2022 - 2024 — McMap. All rights reserved.