This is a template on how to package a simple Python project
- Installation
- Setting Up Your Package
- Installing Dependencies
- Building Your Package
- Publishing to PyPI
To install the package in editable mode (ideal for development), follow these steps:
- Python 3.7 or higher
pip
(ensure it's the latest version)setuptools
42 or higher (for building the package)
First, clone the repository to your local machine:
git clone https://github.com/yourusername/your-package-name.git
cd your-package-name
Create a virtual environment for your package:
python -m venv venv
source venv/bin/activate
Make sure setuptools and pip are up to date:
pip install --upgrade pip setuptools wheel
The pyproject.toml file contains the configuration for building and packaging your Python project. You'll want to customize this to reflect your package's name, version, dependencies, license, etc.
name: The name of your package.
version: The version of your package (e.g., "0.1.0").
dependencies: List any runtime dependencies your package requires (e.g., requests, numpy).
license: Specify your package's license, either as text or a file. For example:
license = { text = "MIT" }
Or, if you have a LICENSE file: license = { file = "LICENSE.txt" }
Edit this README file to reflect your package's functionality.
To install your package in editable mode for development, use the following command:
pip install -e .
This will install the package, allowing you to edit it directly and have changes take effect immediately without reinstalling.
To install any optional dependencies, such as development dependencies, use:
pip install -e .[dev]
To build your package for distribution (e.g., for uploading to PyPI), you can use:
python -m build
This will create .tar.gz and .whl files in the dist/ directory.
To publish your package to PyPI, you can use the twine tool:
pip install twine
twine upload dist/*
You'll need to have a PyPI account and have your credentials set up for this.