Skip to content

Instantly share code, notes, and snippets.

@arsho
Last active June 11, 2024 16:08
Show Gist options
  • Save arsho/fc651bfadd8a0f42be72156fd21bd8a9 to your computer and use it in GitHub Desktop.
Save arsho/fc651bfadd8a0f42be72156fd21bd8a9 to your computer and use it in GitHub Desktop.
Update existing Python package in Pypi

Update PyPI package (Tested on 12/31/2023)

I updated my package autolike today using the following steps:

Update the project locally

  • Changed the version number in setup.py and modify package as necessary.

Test in development

Assuming you’re in the root of your project directory, then run:

pip install -e .

Created a build

pip install --upgrade build  
python -m build  

Generate API Token

Generate API token from https://pypi.org/manage/account/ for your package.

Install twine and upload distribution to Pypi

pip install --upgrade twine
python -m twine upload dist/*

Here you need to use the following credentials

username: __token__
password: <YOUR API TOKEN>

Check if the project is updated on PyPI

You can see if your package has successfully uploaded by navigating to the URL https://pypi.org/project/ where sampleproject is the name of your project that you uploaded. It may take a minute or two for your project to appear on the site.

Old Methond to create the build

Create source distribution

Minimally, you should create a Source Distribution:

python3 setup.py sdist

Create 'wheel'

You should also create a wheel for your project. A wheel is a built package that can be installed without needing to go through the “build” process. Installing wheels is substantially faster for the end user than installing from a source distribution. Universal Wheels are wheels that are pure Python (i.e. contain no compiled extensions) and support Python 2 and 3. This is a wheel that can be installed anywhere by pip.

python3 setup.py bdist_wheel --universal

Only use the --universal setting, if:

  • Your project runs on Python 2 and 3 with no changes (i.e. it does not require 2to3).
  • Your project does not have any C extensions.

Reference

@aahnik
Copy link

aahnik commented Aug 17, 2020

thanks a lot. it's clear and concise helped me a lot. 👍

@RefinedDev
Copy link

Doesn't work for me please help it shows this error.
image

@aahnik
Copy link

aahnik commented Dec 12, 2020

@RefinedDev it is not the problem of script. but your problem.

see the error message: file already exists. Change the name of the package and try again. or change version no. in setup.py

@RefinedDev
Copy link

@RefinedDev it is not the problem of script. but your problem.

see the error message: file already exists. Change the name of the package and try again. or change version no. in setup.py

Ty it worked i'm dumb 👍

@CypherGuy
Copy link

I have an error too. I notice when I run python3 setup.py bdist_wheel --universal, a second file in that folder is made, however, whether I remove it or not, this error pops up.

Screenshot 2021-05-13 at 14 36 47

@aahnik
Copy link

aahnik commented May 13, 2021

hi, @CypherGuy, stop wasting time with these primitive methods. Use a modern package manager like poetry.

With poetry its as simple as:

poetry build && poetry publish

@CypherGuy
Copy link

hi, @CypherGuy, stop wasting time with these primitive methods. Use a modern package manager like poetry.

With poetry its as simple as:

poetry build && poetry publish

If there a link for me to do this? Where do I find docs on it?

@aahnik
Copy link

aahnik commented May 14, 2021

@CypherGuy which era do you live in? Do you know something called a search engine exists? Like Google/DuckDuckGo ?

https://python-poetry.org/

Don't ask questions that you can figure out with a google search.

Google Search

DuckDuckGo search

@CypherGuy
Copy link

CypherGuy commented Nov 30, 2021

@aahnik No need to be a muppet about it, but thanks for the link

@mte0
Copy link

mte0 commented Jun 1, 2022

thanks for this gist! im wondering, is there a way to run python code for a user when the package is installed? ive tried in setup.py but thats obviously for when you built the package, and in the __init__.py only runs when the package is imported... id like to have a little gui with links and info show up when the package is installed

@arsho
Copy link
Author

arsho commented Jun 1, 2022

thanks for this gist! im wondering, is there a way to run python code for a user when the package is installed? ive tried in setup.py but thats obviously for when you built the package, and in the __init__.py only runs when the package is imported... id like to have a little gui with links and info show up when the package is installed

I am not sure if that is possible. I have never seen any GUI after installing a Python package. Have you seen any? If you know any package that displays GUI after installation, let us know. We can then check the project. Interesting idea to be honest!

@AKNEO1000
Copy link

I am getting this error while running the command:

`python3 setup.py bdist_wheel --universal

/Library/Frameworks/Python.framework/Versions/3.10/bin/python3: can't open file '/Users/arsh/Desktop/python projects/Eng_Pyth/Eng-Pyth-ver-0.0.2/eng_pyth/setup.py': [Errno 2] No such file or directory

`

@AKNEO1000
Copy link

pls help me

@Tovborg
Copy link

Tovborg commented Aug 17, 2022

I am getting this error while running the command:

`python3 setup.py bdist_wheel --universal

/Library/Frameworks/Python.framework/Versions/3.10/bin/python3: can't open file '/Users/arsh/Desktop/python projects/Eng_Pyth/Eng-Pyth-ver-0.0.2/eng_pyth/setup.py': [Errno 2] No such file or directory

`

Either it's a problem with the path (python projects have to be in a single word or in quotes), or setup.py doesn't exist or you haven't specified the right path. Hope that helps

@skrvt
Copy link

skrvt commented Jun 8, 2023

my README.md didnt update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment