Sobes.tech
Junior — Middle

How to create an archive package from Python code for distribution or installation?

sobes.tech AI

Answer from AI

To create a distributable archive package of Python code that can be shared and installed, standard tools like setuptools and wheel are typically used.

Main steps:

  1. Create a setup.py file in the root of your project with the package description.

  2. Make sure you have setuptools and wheel installed:

pip install setuptools wheel
  1. Run the command to build the archive:
python setup.py sdist bdist_wheel

After this, archive files .tar.gz and .whl will appear in the dist/ folder, which can be distributed or uploaded to PyPI.

A simple example of setup.py:

from setuptools import setup, find_packages

setup(
    name='mypackage',
    version='0.1',
    packages=find_packages(),
    install_requires=[
        # dependencies
    ],
)

This package can be installed with the command:

pip install dist/mypackage-0.1-py3-none-any.whl