.. _spkg_python3:

python3: The Python programming language
========================================

Description
-----------

By default, Sage will try to use system's ``python3`` to set up a virtual
environment, a.k.a. `venv <https://docs.python.org/3.10/library/venv.html>`_
rather than building a Python 3 installation from scratch.

Sage will accept versions 3.10.x to 3.13.x.

You can also use ``--with-python=/path/to/python3_binary`` to tell Sage to use
``/path/to/python3_binary`` to set up the venv. Note that setting up the venv requires
a number of Python modules to be available within the Python in question. Currently,
as of Sage 10.3, these modules are as follows: ``sqlite3``, ``ctypes``, ``math``,
``hashlib``, ``socket``, ``zlib``, ``ssl``, ``ensurepip``.
For Python >= 3.12, also ``setuptools`` is required; for older Python versions,
``distutils.core`` is required. These modules will be checked for by the ``configure``
script.

Use the ``configure`` option ``--without-system-python3`` if you want Python 3
built from scratch.


Upstream Contact
----------------

https://www.python.org


Type
----

standard


Dependencies
------------

- :ref:`spkg_bzip2`
- :ref:`spkg_libffi`
- :ref:`spkg_liblzma`
- :ref:`spkg_libpng`
- :ref:`spkg_openssl`
- :ref:`spkg_pkgconf`
- :ref:`spkg_readline`
- :ref:`spkg_sqlite`
- :ref:`spkg_xz`
- :ref:`spkg_zlib`

Version Information
-------------------

package-version.txt::

    3.13.6

Equivalent System Packages
--------------------------

.. tab:: Alpine:

   .. CODE-BLOCK:: bash

       $ apk add python3-dev py3-setuptools

.. tab:: Debian/Ubuntu:

   .. CODE-BLOCK:: bash

       $ sudo apt-get install python3 libpython3-dev python3-setuptools \
             python3-venv

.. tab:: Fedora/Redhat/CentOS:

   .. CODE-BLOCK:: bash

       $ sudo dnf install python3-devel python3-setuptools

.. tab:: FreeBSD:

   .. CODE-BLOCK:: bash

       $ sudo pkg install lang/python devel/py-setuptools

.. tab:: Homebrew:

   .. CODE-BLOCK:: bash

       $ brew install python3 python-setuptools

.. tab:: MacPorts:

   .. CODE-BLOCK:: bash

       $ sudo port install python310 py-setuptools

.. tab:: mingw-w64:

   .. CODE-BLOCK:: bash

       $ sudo pacman -S \$\{MINGW_PACKAGE_PREFIX\}-python

.. tab:: openSUSE:

   .. CODE-BLOCK:: bash

       $ sudo zypper install python3\$\{PYTHON_MINOR\}-devel python3\$\{PYTHON_MINOR\}-setuptools

.. tab:: Void Linux:

   .. CODE-BLOCK:: bash

       $ sudo xbps-install python3-devel python3-setuptools

# See https://repology.org/project/python/versions

If the system package is installed, ``./configure`` will check if it can be used.
