|
| 1 | +=============================== |
| 2 | +Running ``setuptools`` commands |
| 3 | +=============================== |
| 4 | + |
| 5 | +Historically, ``setuptools`` allowed running commands via a ``setup.py`` script |
| 6 | +at the root of a Python project, as indicated in the examples below:: |
| 7 | + |
| 8 | + python setup.py --help |
| 9 | + python setup.py --help-commands |
| 10 | + python setup.py --version |
| 11 | + python setup.py sdist |
| 12 | + python setup.py bdist_wheel |
| 13 | + |
| 14 | +You could also run commands in other circumstances: |
| 15 | + |
| 16 | +* ``setuptools`` projects without ``setup.py`` (e.g., ``setup.cfg``-only):: |
| 17 | + |
| 18 | + python -c "import setuptools; setup()" --help |
| 19 | + |
| 20 | +* ``distutils`` projects (with a ``setup.py`` importing ``distutils``):: |
| 21 | + |
| 22 | + python -c "import setuptools; with open('setup.py') as f: exec(compile(f.read(), 'setup.py', 'exec'))" develop |
| 23 | + |
| 24 | +That is, you can simply list the normal setup commands and options following the quoted part. |
| 25 | + |
| 26 | +.. warning:: |
| 27 | + While it is perfectly fine that users write ``setup.py`` files to configure |
| 28 | + a package build (e.g. to specify binary extensions or customize commands), |
| 29 | + on recent versions of ``setuptools``, running ``python setup.py`` directly |
| 30 | + as a script is considered **deprecated**. This also means that users should |
| 31 | + avoid running commands directly via ``python setup.py <command>``. |
| 32 | + |
| 33 | + If you want to create :term:`sdist <Source Distribution (or "sdist")>` or :term:`wheel` |
| 34 | + distributions the recommendation is to use the command line tool provided by :pypi:`build`:: |
| 35 | + |
| 36 | + pip install build # needs to be installed first |
| 37 | + |
| 38 | + python -m build # builds both sdist and wheel |
| 39 | + python -m build --sdist |
| 40 | + python -m build --wheel |
| 41 | + |
| 42 | + Build will automatically download ``setuptools`` and build the package in an |
| 43 | + isolated environment. You can also specify specific versions of |
| 44 | + ``setuptools``, by setting the :doc:`build requirements in pyproject.toml |
| 45 | + </build_meta>`. |
| 46 | + |
| 47 | + If you want to install a package, you can use :pypi:`pip` or :pypi:`installer`:: |
| 48 | + |
| 49 | + pip install /path/to/wheel/file.whl |
| 50 | + pip install /path/to/sdist/file.tar.gz |
| 51 | + pip install . # replacement for python setup.py install |
| 52 | + pip install --editable . # replacement for python setup.py develop |
| 53 | + |
| 54 | + pip install installer # nees to be installed first |
| 55 | + python -m installer /path/to/wheel/file.whl |
| 56 | + |
1 | 57 | ----------------- |
2 | 58 | Command Reference |
3 | 59 | ----------------- |
|
0 commit comments