A private Python package is a package that is not published on the public Python Package Index (PyPI) and is intended for restricted use, typically within an organization, team, or individual project.
1. Python package saved on your local machine
We are going to install a private package named “basics” in the virtual environment of our Django project “mysite”.
The Python package is saved in the home directory, at the same level of the Django project.
Open the Ubuntu terminal and activate the virtual environment
cd mysite ls -la
source env/bin/activate
Go to the dist directory of the Python package
cd ~/basics/dist ls -la
The dist directory in a Python package is a folder where the distribution files of the package are stored after building the package.
These distribution files are what you share with others, upload to a package repository (like PyPI), or install using a package manager like pip.
There are typically two main types of distribution files you might find in the dist directory:
- - Source Distribution or sdist (.tar.gz or .zip)
- - Built Distribution, commonly called wheel (.whl)
A wheel is a ZIP archive. You can inspect its contents by unpacking it as a normal ZIP archive using unzip or from the command line with the Python’s zipfile module.
To list the files in the archive:
python3 -m zipfile -l basics-1.0.0-py3-none-any.whl
To extract the files from the archive in the current directory:
python3 -m zipfile -e basics-1.0.0-py3-none-any.whl ./
Inside a wheel, you will find the package’s files, plus an additional directory called package_name-version.dist-info, in this case basics-1.0.0.dist-info.
This directory contains various files, including a METADATA file which holds the project metadata, as well as a RECORD that lists all files in the wheel along with a hash of their content, as a safety check of the download’s integrity.
We’ll use the .whl file to install our package.
pip3 install basics-1.0.0-py3-none-any.whl
Run the following command to list all the packages installed so far
pip3 freeze
2. Python package saved in GitHub repository
Log in to GitHub from the Ubuntu terminal
gh auth login
Install your private Python package with pip
1) SSH versionpip install git+ssh://git@github.com/username/repo.git2) HTTPS version
pip install git+https://github.com/username/repo.git