{"id":352,"date":"2023-01-04T21:56:43","date_gmt":"2023-01-04T21:56:43","guid":{"rendered":"https:\/\/cloasdata.de\/?p=352"},"modified":"2023-01-05T22:33:57","modified_gmt":"2023-01-05T22:33:57","slug":"build-python-3-11-on-raspberry-pi-from-source","status":"publish","type":"post","link":"https:\/\/cloasdata.de\/?p=352","title":{"rendered":"Build python 3.11 on raspberry pi from source"},"content":{"rendered":"\n<p>The recent version of Python is 3.11 and was released in December 2022. Typical the raspbian distribution ships with lot older python releases for example buster comes with python 3.7. <br>Of course there are many cases where you want to use the most recent version of python. For example comes with a significant speed optimization.<br>This post gives you a very compressed script to be able to build python on you own.<\/p>\n\n\n\n<p>First we should start with a updating all packages<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo apt update\nsudo apt upgrade<\/code><\/pre>\n\n\n\n<p>Now we need to install all dependencies required to compile python from source.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo apt install -y libffi-dev libbz2-dev liblzma-dev \\\n    libsqlite3-dev libncurses5-dev libgdbm-dev zlib1g-dev \\\n    libreadline-dev libssl-dev tk-dev build-essential \\\n    libncursesw5-dev libc6-dev openssl git<\/code><\/pre>\n\n\n\n<p>Download the current version from <a href=\"https:\/\/www.python.org\/downloads\/release\/python-3111\/\">python.org<\/a>. In this example I&#8217;m downloading 3.11.1.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">wget https:\/\/www.python.org\/ftp\/python\/3.11.1\/Python-3.11.1.tar.gz\ntar zxf Python-3.11.1.tgz\ncd Python-3.11.1<\/code><\/pre>\n\n\n\n<p>Build the makefile (will take several minutes)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">.\/configure --enable-optimizations<\/code><\/pre>\n\n\n\n<p>We are ready to make python (compile, link, test etc.). The below shown arguments of <code>make<\/code> should help to compile as fast as possible. But it still will take between .5 to 1 hour. Also, like in my case, it could be possible that rpi hangs to dead. Restart and repeat.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">make -j 4 -l 4<\/code><\/pre>\n\n\n\n<p>make will inform you about which python modules where not compile able. Check if this is relevant for your case. In most cases this means that some dependencies (libraries) are missing.<\/p>\n\n\n\n<p>Test the build shortly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">cd python\npython -V\n&gt;&gt;&gt; Python 3.11.1\ncd ..<\/code><\/pre>\n\n\n\n<p>With that we are ready to install python regular onto the rpi<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"Python\" class=\"language-Python\">make install<\/code><\/pre>\n\n\n\n<p>Python 3.11.1 should be now you default Python 3 release. You may clean up remove the temporary folder and remove also above dependencies if you like.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"Python\" class=\"language-Python\">python3\n&gt;&gt;&gt; import sys\n&gt;&gt;&gt; sys.version\n# 3.11.1 ...<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The recent version of Python is 3.11 and was released in December 2022. Typical the raspbian distribution ships with lot older python releases for example buster comes with python 3.7. Of course there are many cases where you want to use the most recent version of python. For example comes with a significant speed optimization.This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":358,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[4],"tags":[5,16],"class_list":["post-352","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-python","tag-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/cloasdata.de\/index.php?rest_route=\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloasdata.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloasdata.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloasdata.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloasdata.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=352"}],"version-history":[{"count":3,"href":"https:\/\/cloasdata.de\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":357,"href":"https:\/\/cloasdata.de\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions\/357"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloasdata.de\/index.php?rest_route=\/wp\/v2\/media\/358"}],"wp:attachment":[{"href":"https:\/\/cloasdata.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloasdata.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloasdata.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}