I have gone through already available answers in SO but nothing seems working for me.
I am following python commands to upload my package(Note: I am a new user and have registered the account with username and password):
Create setup.py:
from setuptools import setup
setup(
name='', # This is the name of your PyPI-package.
version='0.1', # Update the version number for new releases
scripts=[''] # The name of your script, and also the command you'll be using for calling it
)
Package the script:
python setup.py sdist
Register the account:
python setup.py register
This prompted me below message(I choose 2nd as I am new user):
1. use your existing login,
2. register as a new user,
3. have the server generate a new password for you (and email it to you), or
4. quit
Your selection [default 1]:
Upload the package:
python setup.py sdist upload
After trying steps I got the error while uploading:
Upload failed (403): Invalid or non-existent authentication information.
error: Upload failed (403): Invalid or non-existent authentication information.
After a lot of trial and error, I found the simple solution. Also, @hoefling answer helps me to solve them.
Register as a user in https://pypi.org/ and use register account command which mentioned in the question.
Now, Three magic steps which will resolve the issue.
pip install twine
python setup.py sdist
# This will ask for you username and password
twine upload dist/*
EDIT:
If you want to upgrade your package, just follow the below simple steps:
build
, dist
, and <package name>.egg-info
folders in your root directory.setup.py
file.python setup.py sdist bdist_wheel
twine upload dist/*
First of all, note that register
is deprecated and not necessary anymore. When trying to register a package on PyPI, you should get a message:
Server response (410): This API is no longer supported, instead simply upload the file.
Just skip the register step and proceed with the uploading.
distutils
/setuptools
Create a file $HOME/.pypirc
with the contents:
[distutils]
index-servers =
pypi
[pypi]
username: <username>
password: <password>
and repeat the upload:
$ python setup.py sdist upload
Thing is, the distutils
' upload
subcommand doesn't provide an option to enter the credentials from command line, instead completely relying on the .pypirc
file.
twine
If storing credentials in plain text format is not your thing, twine
provides a possibility of entering credentials from command line. This is also the officially recommended tool for uploading packages.
Install twine
:
$ pip install twine
Build the package:
$ python setup.py clean sdist
Upload:
$ twine upload dist/*
The tool will ask you for the username and password.
twine
also lets you provide the credentials in environment variables:
$ TWINE_USERNAME=me TWINE_PASSWORD=passwd twine upload dist/*
or via keyring.
Create a file in home dir by touch ~/.pypirc
similar look like: added pytest optionally
[distutils]
index-servers =
pypi
pypitest
[pypi]
repository=https://pypi.python.org/pypi
username=your_username
password=your_password
[pypitest]
repository=https://testpypi.python.org/pypi
username=your_username
password=your_password
403: Invalid or non-existent authentication information
If there is a %
in your password just type it without escaping; e.g. Hello%123
If there is a space character in your password just type it without quotes; e.g. Hello 123
python setup.py register -r pypi
python setup.py sdist upload -r pypi
From official doc
First, you need a PyPI user account
To change to the new PyPI authentication method, go to https://pypi.org/manage/account/token/
Login to your account and you'll see
Give the token a name, select the Scope (i.e. what repository do you allow the Token to be used for).
Then copy the token as the password in your ~/.pypirc
file, use __token__
as the username, e.g.
[distutils]
index-servers =
pypi
testpypi
[pypi]
username: __token__
password: pypi-12837192048i1234...
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