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:
-
Create a
setup.pyfile in the root of your project with the package description. -
Make sure you have
setuptoolsandwheelinstalled:
pip install setuptools wheel
- 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