Python - Regular Package (Shipping | Packaging)

> Procedural Languages > Python > Python - (Shipping|Packaging)

1 - About


3 - Steps

With python 3.

3.1 - Structure


name = "hello_nico"

3.2 - Building a distribution

3.2.1 - Update the building tool

  • run this command from the package directory (where is located) ???
python -m pip install --user --upgrade setuptools wheel



3.2.2 - Build

cd ./project
python sdist bdist_wheel


This will create 3 sub directories:

  • build
  • dist
  • hello_nico.egg-info

The most important are in the dist subdirectory:



Note: the full output of the command is:

running sdist
running egg_info
writing hello_nico.egg-info\PKG-INFO
writing dependency_links to hello_nico.egg-info\dependency_links.txt
writing top-level names to hello_nico.egg-info\top_level.txt
reading manifest file 'hello_nico.egg-info\SOURCES.txt'
writing manifest file 'hello_nico.egg-info\SOURCES.txt'
running check
creating hello-nico-0.0.2
creating hello-nico-0.0.2\hello_nico.egg-info
creating hello-nico-0.0.2\hello_nico_pkg
copying files to hello-nico-0.0.2...
copying -> hello-nico-0.0.2
copying -> hello-nico-0.0.2
copying hello_nico.egg-info\PKG-INFO -> hello-nico-0.0.2\hello_nico.egg-info
copying hello_nico.egg-info\SOURCES.txt -> hello-nico-0.0.2\hello_nico.egg-info
copying hello_nico.egg-info\dependency_links.txt -> hello-nico-0.0.2\hello_nico.egg-info
copying hello_nico.egg-info\top_level.txt -> hello-nico-0.0.2\hello_nico.egg-info
copying hello_nico_pkg\ -> hello-nico-0.0.2\hello_nico_pkg
Writing hello-nico-0.0.2\setup.cfg
creating dist
Creating tar archive
removing 'hello-nico-0.0.2' (and everything under it)
running bdist_wheel
running build
running build_py
installing to build\bdist.win32\wheel
running install
running install_lib
creating build\bdist.win32\wheel
creating build\bdist.win32\wheel\hello_nico_pkg
copying build\lib\hello_nico_pkg\ -> build\bdist.win32\wheel\.\hello_nico_pkg
running install_egg_info
Copying hello_nico.egg-info to build\bdist.win32\wheel\.\hello_nico-0.0.2-py3.7.egg-info
running install_scripts
creating build\bdist.win32\wheel\hello_nico-0.0.2.dist-info\WHEEL
creating 'dist\hello_nico-0.0.2-py3-none-any.whl' and adding 'build\bdist.win32\wheel' to it
adding 'hello_nico_pkg/'
adding 'hello_nico-0.0.2.dist-info/METADATA'
adding 'hello_nico-0.0.2.dist-info/WHEEL'
adding 'hello_nico-0.0.2.dist-info/top_level.txt'
adding 'hello_nico-0.0.2.dist-info/RECORD'
removing build\bdist.win32\wheel

3.3 - Upload

3.3.1 - Create an account to the repo

Create an account on Test PyPI.

3.3.2 - Update the deploy tool

  • twine upload the archive to Test PyPI
python -m pip install --user --upgrade twine
REM Optional Add the scripts location to the path
set PATH=C:\Users\gerard\AppData\Roaming\Python\Python37\Scripts;%PATH%

3.3.3 - Deploy

  • upload all of the archives under the dist sub-directory.
twine upload --repository-url dist/*
Enter your username: gerardnico
Enter your password:
Uploading distributions to
Uploading hello_nico-0.0.1-py3-none-any.whl
100%| 4.48k/4.48k [00:01<00:00, 2.88kB/s]
Uploading hello nico-0.0.1.tar.gz
100%| 4.23k/4.23k [00:01<00:00, 3.16kB/s]

It may take a minute or two for your project to appear on the site.

The package can be then see at:

Tintin ! In our case:

On the real index, you can see if your package has successfully uploaded by navigating to the URL<projecName>

3.3.4 - Use it

  • Syntax
python -m pip install --index-url packageName
cd c:\tmp
mkdir venv
cd venv
Scripts\python -m pip install --index-url hello-nico
Looking in indexes:
Collecting hello-nico
Installing collected packages: hello-nico
Successfully installed hello-nico-0.0.1
  • The package was installed
ls Lib\site-packages\hello_nico-0.0.1.dist-info

3.4 - Import to test

  • Start Python
  • Import the module and access the property defined in the file
import hello_nico_pkg

4 - Documentation / Reference