
{"id":44029,"date":"2023-05-26T13:55:56","date_gmt":"2023-05-26T13:55:56","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=44029"},"modified":"2026-05-29T08:32:51","modified_gmt":"2026-05-29T08:32:51","slug":"install-python-3-12-ubuntu","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2023\/05\/install-python-3-12-ubuntu\/","title":{"rendered":"How to Install Python (3.15 Beta) in Ubuntu 26.04, 24.04, 22.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/10\/python-feature-icon.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-34796\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/10\/python-feature-icon-250x250.png\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/10\/python-feature-icon-250x250.png 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/10\/python-feature-icon-300x300.png 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/10\/python-feature-icon-600x600.png 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/10\/python-feature-icon-768x768.png 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/10\/python-feature-icon.png 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>For developers who want to prepare their project for the latest Python releases, here&#8217;s how to install the current Python 3.15 pre-release in all current Ubuntu releases.<\/p>\n<p>Python 3.15 is so far in the development stage, which features explicit lazy imports for faster startup times, <code>frozendict<\/code> and <code>sentinel<\/code> built-in types, a dedicated profiling package for organizing Python profiling tools, new <code>PyBytesWriter<\/code> C API to create a Python bytes object, and more. See the <a href=\"https:\/\/docs.python.org\/3.15\/whatsnew\/3.15.html\" target=\"_blank\" rel=\"noopener\">what&#8217;s new<\/a> page for details.<\/p>\n<h3>How to Install Python 3.15 (Pre-release So far)<\/h3>\n<p>Python is easy to install in Ubuntu by either using the popular Deadsnakes PPA or building from the source. Choose either one that you prefer.<\/p>\n<h4>Option 1: Install Python 3.15 from PPA<\/h4>\n<p>For Ubuntu 22.04, Ubuntu 24.04, Ubuntu 26.04 and their derivatives such as Linux Mint 21\/22, the <a href=\"https:\/\/launchpad.net\/~deadsnakes\/+archive\/ubuntu\/ppa\/\" target=\"_blank\" rel=\"noopener\">Deadsnakes PPA<\/a> has made the packages for all supported CPU architecture types: amd64, arm64\/armhf, ppc64el, and s390x.<\/p>\n<p><b>1.<\/b> First, press <b>Ctrl+Alt+T<\/b> on keyboard to open terminal. Then paste the command below and hit run to add PPA:<\/p>\n<pre>sudo add-apt-repository ppa:deadsnakes\/ppa<\/pre>\n<p><i>Type user password (no asterisk feedback) when it asks and hit Enter to continue.<\/i><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51300\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/deaksnake-ppa2604-700x446.webp\" alt=\"\" width=\"610\" height=\"389\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/deaksnake-ppa2604-700x446.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/deaksnake-ppa2604-300x191.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/deaksnake-ppa2604-768x489.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/deaksnake-ppa2604.webp 828w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><br \/>\n<b>2.<\/b> Then refresh package cache. It should be done automatically during adding PPA, though Linux Mint user may need to do this job manually by running command:<\/p>\n<pre>sudo apt update<\/pre>\n<p><b>3.<\/b> Finally, run command to install Python 3.15:<\/p>\n<pre>sudo apt install python3.15-full<\/pre>\n<p>As you see in the screenshot, this command will install Python 3.15 as well as the dbm database, Tk applications, and pyvenv binary support.<\/p>\n<p>You may also install <code>idle-python3.15<\/code> package for the default IDE using Tkinter, or replace <code>python3.15-full<\/code> with <code>python3.15<\/code> for the minimal install.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51301\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/apt-python315full-700x455.webp\" alt=\"\" width=\"610\" height=\"397\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/apt-python315full-700x455.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/apt-python315full-300x195.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/apt-python315full-768x499.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/apt-python315full.webp 809w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<h4>Option 2: Compile and install Python 3.15 from source<\/h4>\n<p>Don&#8217;t trust third-party repositories or you&#8217;re running Ubuntu 20.04 or Ubuntu 18.04 that PPA does not support? It&#8217;s easy to build Python from the source tarball.<\/p>\n<p><b>1.<\/b> First download the source tarball from its ftp download page:<\/p>\n<div class=\"wp-block-buttons aligncenter\">\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link has-vivid-cyan-blue-to-vivid-purple-gradient-background has-text-color has-background\" href=\"https:\/\/www.python.org\/ftp\/python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python FTP Download Page<\/a><\/div>\n<\/div>\n<p><b>2.<\/b> Then open &#8216;Downloads&#8217; folder, extract the source tarball, finally right-click on source folder and select &#8220;Open in Terminal&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51302\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/open-python315terminal-700x464.webp\" alt=\"\" width=\"610\" height=\"404\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/open-python315terminal-700x464.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/open-python315terminal-300x199.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/open-python315terminal-768x509.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/open-python315terminal.webp 894w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p><b>3.<\/b> When terminal opens, run the command below to install the dependency libraries for building the source:<\/p>\n<pre>sudo apt install wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev<\/pre>\n<p>Then, run commands below one by one to configure and build Python:<\/p>\n<pre>.\/configure --enable-optimizations<\/pre>\n<pre>sudo make -j8 &amp;&amp; sudo make altinstall<\/pre>\n<h3>Verify:<\/h3>\n<p>Once installed Python 3.15, verify by running command:<\/p>\n<pre>python3.15 --version &amp;&amp; pip3.15 --version<\/pre>\n<h3>Set Python 3.15 as default (for PPA package)<\/h3>\n<p><b>NOTE: If you built Python 3.15 from source via the steps above, then it should be already set as default. Try running <code>python3 --verison<\/code> to verify!<\/b><\/p>\n<p>It&#8217;s NOT recommended to set non-preinstalled Python package as default for Python3, because it may break some applications.<\/p>\n<p>If you insist, try to set <code>python3.15<\/code> as default by running the commands below one by one:<\/p>\n<ul>\n<li>First, run command below to check the pre-installed (current default) Python verison:\n<pre>python3 --version<\/pre>\n<p>It&#8217;s version <code>3.14<\/code> for Ubuntu 26.04, <code>3.12<\/code> for 24.04, or <code>3.10<\/code> for 22.04.<\/li>\n<li>Then, run command below to add <code>\/etc<\/code> alternatives for default python3 (<b>replace version 3.14 with your Ubuntu&#8217;s default version number<\/b>):\n<pre>sudo update-alternatives --install \/usr\/bin\/python3 python3 \/usr\/bin\/python3.14 100<\/pre>\n<p>And, add Python 3.15 as an alternative link to python (replace <code>\/usr\/bin\/python3.15<\/code> according last command output).<\/p>\n<pre>sudo update-alternatives --install \/usr\/bin\/python3 python3 \/usr\/bin\/python3.15 1<\/pre>\n<\/li>\n<li>Finally, run command below to configure default for <code>python3<\/code>:\n<pre>sudo update-alternatives --config python3<\/pre>\n<p>After that, run <code>python3 --version<\/code> to verify. And, you may re-run the last command at anytime to switch the default back to the pre-installed one.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51303\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/python315-default-700x452.webp\" alt=\"\" width=\"610\" height=\"394\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/python315-default-700x452.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/python315-default-300x194.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/python315-default-768x496.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/python315-default.webp 806w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/li>\n<\/ul>\n<h3>Use pip installer for Python 3.15<\/h3>\n<p>Due to <a href=\"https:\/\/peps.python.org\/pep-0668\/\" target=\"_blank\" rel=\"noopener\">PEP 668<\/a>, <code>pip install<\/code> does no longer work like before. The recommended way to use pip is create a virtual environment first, though there are <a href=\"https:\/\/ubuntuhandbook.org\/index.php\/2024\/03\/pip-install-error-ubuntu-2404\/\" target=\"_blank\" rel=\"noopener\">few workarounds<\/a>.<\/p>\n<p>First run command to install the pyvenv binary (if you installed the package from PPA):<\/p>\n<pre>sudo apt-get install python3.15-venv<\/pre>\n<p>Then, create a virtual environment by running command:<\/p>\n<pre>python3.15 -m venv ~\/.venv\/mypythonapp<\/pre>\n<p>This command will create a <code>.venv<\/code> hidden folder in your user home folder then create a virtual environment called <code>mypythonapp<\/code> (replace the name as you want).<\/p>\n<p>Next, use the source command to get into that virtual environment:<\/p>\n<pre>source ~\/.venv\/mypythonapp\/bin\/activate<\/pre>\n<p>Finally, run <code>pip<\/code> command to install a python package.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-51304\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/source-pip315-700x442.webp\" alt=\"\" width=\"610\" height=\"385\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/source-pip315-700x442.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/source-pip315-300x189.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/source-pip315-768x485.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/05\/source-pip315.webp 835w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p><b>Tips:<\/b> Without running <code>source<\/code> command every time, you may optionally add that virtual environment into PATH, so it can be run in anywhere in terminal.<\/p>\n<p>To do so, either run command below, which works for the terminal window only, or paste it into the end of <b>.profile<\/b> file (press Ctrl+H in user home to view it) and log-out and back in.<\/p>\n<pre>export PATH=$HOME\/.venv\/mypythonapp\/bin:$PATH<\/pre>\n<h3>Uninstall Python 3.15:<\/h3>\n<p>If you installed Python 3.15 using the PPA repository, simply open terminal and run command to remove it:<\/p>\n<pre>sudo apt remove --autoremove python3.15 python3.15-full<\/pre>\n<p>For the PPA, run command to remove it:<\/p>\n<pre>sudo add-apt-repository --remove ppa:deadsnakes\/ppa<\/pre>\n<p>If you built the Python 3.15 from source tarball, then there&#8217;s no uninstaller script to automate the job.<\/p>\n<p>However, you may manually remove the installed files by running commands:<\/p>\n<pre>cd \/usr\/local\/bin &amp;&amp; sudo rm python3* pip3* idle3* pydoc3*<\/pre>\n<pre>cd \/usr\/local\/lib &amp;&amp; sudo rm -R python3.15 pkgconfig\/python* libpython3.15.a<\/pre>","protected":false},"excerpt":{"rendered":"<p>For developers who want to prepare their project for the latest Python releases, here&#8217;s how to install the current Python 3.15 pre-release in all current Ubuntu releases. Python 3.15 is so far in the development stage, which features explicit lazy imports for faster startup times, frozendict and sentinel built-in types, a dedicated profiling package for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":34796,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[2045],"class_list":["post-44029","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-python"],"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/44029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=44029"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/44029\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/34796"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=44029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=44029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=44029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}