Follow the below steps to Upload Your Python Package to PyPI
1️⃣ Install the required tools
You only need three tools: pip install setuptools wheel twine build
setuptools → packaging backend
wheel → builds .whl files
twine → securely uploads to PyPI
build → modern build command
2️⃣ Prepare your project structure
A clean, PyPI‑ready structure looks like:
Code
your_package/ │ ├── src/ │ └── your_package/ │ ├── __init__.py │ └── your_code.py │ ├── pyproject.toml ├── README.md ├── LICENSE └── MANIFEST.in (optional)
3️⃣ Fill out pyproject.toml
Example:
toml
[build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project] name = "your-package-name" version = "0.1.0" description = "Short description" readme = "README.md" license = {text = "MIT"} authors = [{name="Your Name", email="you@example.com"}] requires-python = ">=3.8"
This file tells PyPI everything about your package.
4️⃣ Build the package
Run: python -m build
This creates: dist/ your_package‑0.1.0.tar.gz your_package‑0.1.0‑py3‑none‑any.whl
These are the files you will upload.
5️⃣ Create a PyPI API token
Log in to https://pypi.org
Go to Account Settings → API Tokens
Create a token with “Entire account” scope
Copy it — you won’t see it again
6️⃣ Upload to PyPI using Twine
Run: twine upload dist/*
When prompted for username/password:
username: __token__
password: paste your API token
This securely uploads your package to PyPI.
7️⃣ Verify installation
After upload: pip install your-package-name
If it installs successfully, your upload worked! 🎉
⭐ Quick Summary Table
1. Install packaging toolspip install build twine
2. Create project structuresrc/your_package/
3. Add metadatapyproject.toml
4. Build packagepython -m build
5. Create API tokenPyPI website
6. Uploadtwine upload dist/*
7. Test installpip install your-package
You can encounter problems while installing,
1.❗ The error means: Twine is not installed or not on PATH
Let’s fix it cleanly and get your package uploaded.
✅ A. Install Twine properly
Run this in Command Prompt or PowerShell: pip install twine
If you’re using Python 3.11+, sometimes pip points to a different Python.
So also try: py -m pip install twine
After installation, verify: twine --version
If this prints a version number, you’re good.
🛠️ B. If Twine is installed but still not recognized
This means your Python Scripts folder is not on PATH.
Find your Scripts folder: Typical locations:
C:\Users\<yourname>\AppData\Local\Programs\Python\Python311\Scripts
C:\Users\<yourname>\AppData\Local\Programs\Python\Python310\Scripts
Inside that folder you should see: " twine.exe"
Add this folder to PATH:
Open Start → Edit the system environment variables
Click Environment Variables
Under User variables, select Path
Click Edit
Add the Scripts folder path
Close and reopen Command Prompt
Now test again: twine --version
🚀 C. Upload your package
Once Twine works, run: " twine upload dist/* "
When prompted:
username: __token__
password: your PyPI API token
------------
Sometimes, there can be an issue - " when Windows has multiple Python versions installed" , and the system doesn’t know which Scripts folder contains twine.exe.
To fix such issues->
🌟 Step 1 — Find where Python is actually installed
Run this in Command Prompt: "where python"
Then: "where pip"
These two commands tell us the real installation path Windows is using.
You will see something like:
Code
C:\Users\pc\AppData\Local\Programs\Python\Python313\python.exe C:\Users\pc\AppData\Local\Programs\Python\Python313\Scripts\pip.exe
The Scripts folder next to that Python installation is where twine.exe will be.
🌟 Step 2 — Find Twine’s actual location
Run: py -m pip show twine
Look for the line: Location:
C:\Users\pc\AppData\Local\Programs\Python\Python313\Lib\site-packages
Then check the Scripts folder next to it:
C:\Users\pc\AppData\Local\Programs\Python\Python313\Scripts
Inside that folder you should see: "twine.exe"
If you see it, great — we just need to add this folder to PATH.
🌟 Step 3 — Add the correct Scripts folder to PATH
Open Start → Edit the system environment variables
Click Environment Variables
Under User variables, select Path
Click Edit
Click New
Paste the Scripts folder path: C:\Users\pc\AppData\Local\Programs\Python\Python313\Scripts
Save everything
Close and reopen Command Prompt
Now test: "twine --version"
If it prints a version number, you’re done.
🌟 Step 4 — If Twine still doesn’t appear, force‑install it into the correct Python
Run:" py -m pip install --force-reinstall twine"
Then check again: "twine --version"
Thanks,