1.. highlightlang:: sh 2 3.. _using-on-unix: 4 5******************************** 6 Using Python on Unix platforms 7******************************** 8 9.. sectionauthor:: Shriphani Palakodety 10 11 12Getting and installing the latest version of Python 13=================================================== 14 15On Linux 16-------- 17 18Python comes preinstalled on most Linux distributions, and is available as a 19package on all others. However there are certain features you might want to use 20that are not available on your distro's package. You can easily compile the 21latest version of Python from source. 22 23In the event that Python doesn't come preinstalled and isn't in the repositories as 24well, you can easily make packages for your own distro. Have a look at the 25following links: 26 27.. seealso:: 28 29 https://www.debian.org/doc/manuals/maint-guide/first.en.html 30 for Debian users 31 https://en.opensuse.org/Portal:Packaging 32 for OpenSuse users 33 https://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html 34 for Fedora users 35 http://www.slackbook.org/html/package-management-making-packages.html 36 for Slackware users 37 38 39On FreeBSD and OpenBSD 40---------------------- 41 42* FreeBSD users, to add the package use:: 43 44 pkg install python3 45 46* OpenBSD users, to add the package use:: 47 48 pkg_add -r python 49 50 pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz 51 52 For example i386 users get the 2.5.1 version of Python using:: 53 54 pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz 55 56 57On OpenSolaris 58-------------- 59 60You can get Python from `OpenCSW <https://www.opencsw.org/>`_. Various versions 61of Python are available and can be installed with e.g. ``pkgutil -i python27``. 62 63 64.. _building-python-on-unix: 65 66Building Python 67=============== 68 69If you want to compile CPython yourself, first thing you should do is get the 70`source <https://www.python.org/downloads/source/>`_. You can download either the 71latest release's source or just grab a fresh `clone 72<https://devguide.python.org/setup/#getting-the-source-code>`_. (If you want 73to contribute patches, you will need a clone.) 74 75The build process consists in the usual :: 76 77 ./configure 78 make 79 make install 80 81invocations. Configuration options and caveats for specific Unix platforms are 82extensively documented in the :source:`README.rst` file in the root of the Python 83source tree. 84 85.. warning:: 86 87 ``make install`` can overwrite or masquerade the :file:`python3` binary. 88 ``make altinstall`` is therefore recommended instead of ``make install`` 89 since it only installs :file:`{exec_prefix}/bin/python{version}`. 90 91 92Python-related paths and files 93============================== 94 95These are subject to difference depending on local installation conventions; 96:envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``) 97are installation-dependent and should be interpreted as for GNU software; they 98may be the same. 99 100For example, on most Linux systems, the default for both is :file:`/usr`. 101 102+-----------------------------------------------+------------------------------------------+ 103| File/directory | Meaning | 104+===============================================+==========================================+ 105| :file:`{exec_prefix}/bin/python3` | Recommended location of the interpreter. | 106+-----------------------------------------------+------------------------------------------+ 107| :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories | 108| :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. | 109+-----------------------------------------------+------------------------------------------+ 110| :file:`{prefix}/include/python{version}`, | Recommended locations of the directories | 111| :file:`{exec_prefix}/include/python{version}` | containing the include files needed for | 112| | developing Python extensions and | 113| | embedding the interpreter. | 114+-----------------------------------------------+------------------------------------------+ 115 116 117Miscellaneous 118============= 119 120To easily use Python scripts on Unix, you need to make them executable, 121e.g. with 122 123.. code-block:: shell-session 124 125 $ chmod +x script 126 127and put an appropriate Shebang line at the top of the script. A good choice is 128usually :: 129 130 #!/usr/bin/env python3 131 132which searches for the Python interpreter in the whole :envvar:`PATH`. However, 133some Unices may not have the :program:`env` command, so you may need to hardcode 134``/usr/bin/python3`` as the interpreter path. 135 136To use shell commands in your Python scripts, look at the :mod:`subprocess` module. 137 138 139Editors and IDEs 140================ 141 142There are a number of IDEs that support Python programming language. 143Many editors and IDEs provide syntax highlighting, debugging tools, and :pep:`8` checks. 144 145Please go to `Python Editors <https://wiki.python.org/moin/PythonEditors>`_ and 146`Integrated Development Environments <https://wiki.python.org/moin/IntegratedDevelopmentEnvironments>`_ 147for a comprehensive list. 148