{"id":945,"date":"2026-09-17T23:52:45","date_gmt":"2026-09-17T20:52:45","guid":{"rendered":"https:\/\/imaxis.ru\/?p=945"},"modified":"2026-09-18T00:10:06","modified_gmt":"2026-09-17T21:10:06","slug":"ustanovka-i-ispolzovanie-python-na-ubuntu-versii-pip-venv-systemd","status":"publish","type":"post","link":"https:\/\/imaxis.ru\/?p=945","title":{"rendered":"\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Python \u043d\u0430 Ubuntu: \u0432\u0435\u0440\u0441\u0438\u0438, pip, venv, systemd"},"content":{"rendered":"<h1>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Python \u043d\u0430 Ubuntu: \u0432\u0435\u0440\u0441\u0438\u0438, pip, venv, systemd<\/h1>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 Python \u043d\u0430 Ubuntu\/Debian, \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438, \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f\u043c\u0438, \u0430\u0432\u0442\u043e\u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438 \u0442\u0438\u043f\u043e\u0432\u044b\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438.<\/p>\n<hr \/>\n<h2>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Python<\/h2>\n<p><strong>\u0430) \u041d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439:<\/strong><\/p>\n<pre><code class=\"language-bash\">apt update\napt search --names-only '^python[.0-9]{3,4}$'\napt install python3.12\n<\/code><\/pre>\n<p><strong>\u0431) \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 (deadsnakes):<\/strong><\/p>\n<pre><code class=\"language-bash\">apt install software-properties-common\nadd-apt-repository ppa:deadsnakes\/ppa\nPY_VER=3.12\napt install python${PY_VER}\n<\/code><\/pre>\n<p><strong>PPA deadsnakes \u0434\u0430\u0451\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0432\u0435\u0436\u0438\u043c \u0438 \u0441\u0442\u0430\u0440\u044b\u043c \u0432\u0435\u0440\u0441\u0438\u044f\u043c Python, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 Ubuntu.<\/strong><\/p>\n<hr \/>\n<h2>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0441\u0438\u0439 \u0438 \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h2>\n<pre><code class=\"language-bash\">python --version\n<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044e \u0432 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b:<\/p>\n<pre><code class=\"language-bash\">update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python${PY_VER} 0\n<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"language-bash\">update-alternatives --config python\n<\/code><\/pre>\n<p><strong>\u0415\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044f, \u0443\u0432\u0438\u0434\u0438\u043c:<\/strong><\/p>\n<pre><code>There is only one alternative in link group python (providing \/usr\/bin\/python): \/usr\/bin\/python3.12\nNothing to configure.\n<\/code><\/pre>\n<hr \/>\n<h2>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439<\/h2>\n<p>\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u2014 <code>pip<\/code>. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e:<\/p>\n<pre><code class=\"language-bash\">curl -sS https:\/\/bootstrap.pypa.io\/get-pip.py | python3\npython3 -m pip install django\n<\/code><\/pre>\n<p><strong>\u041d\u0430 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 Ubuntu \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 <code>apt install python3-pip<\/code> \u2014 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 pip \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0432\u043d\u0435\u0448\u043d\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u0441\u0440\u0435\u0434\u043e\u0439 (PEP 668).<\/strong><\/p>\n<hr \/>\n<h2>\u0412\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0418\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0434\u0430\u0451\u0442 \u0441\u0432\u043e\u044e \u0432\u0435\u0440\u0441\u0438\u044e Python \u0438 \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u2014 \u043d\u0430\u0434\u0451\u0436\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<pre><code class=\"language-bash\">PY_VER=3.12\napt install python${PY_VER}-venv\n<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"language-bash\">python${PY_VER} -m venv venv\n<\/code><\/pre>\n<p><strong>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441: <code>python -m venv &lt;\u043a\u0430\u0442\u0430\u043b\u043e\u0433&gt;<\/code>.<\/strong><\/p>\n<p>\u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"language-bash\">source venv\/bin\/activate\n<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435 \u0441\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043d\u0430 <code>(venv) ...<\/code>.<\/strong><\/p>\n<pre><code class=\"language-bash\">pip install -r requirements.txt\ndeactivate\n<\/code><\/pre>\n<hr \/>\n<h2>\u0410\u0432\u0442\u043e\u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 systemd<\/h2>\n<pre><code class=\"language-bash\">vi \/etc\/systemd\/system\/my-app.service\n<\/code><\/pre>\n<pre><code class=\"language-ini\">[Unit]\nDescription=my-app service\nWants=network.target\nAfter=syslog.target network-online.target\n\n[Service]\nType=simple\nWorkingDirectory=\/opt\/my-app\nExecStart=\/opt\/my-app\/venv\/bin\/python .\/app.py\nRestart=on-failure\nRestartSec=10\nKillMode=process\n\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <code>my-app<\/code> \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 <code>\/opt\/my-app<\/code>, \u0437\u0430\u043f\u0443\u0441\u043a \u0438\u0437 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f.<\/strong><\/p>\n<pre><code class=\"language-bash\">systemctl daemon-reload\nsystemctl enable --now my-app\nsystemctl status my-app\n<\/code><\/pre>\n<hr \/>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c<\/h2>\n<h3>fatal error: Python.h<\/h3>\n<pre><code>fatal error: Python.h: No such file or directory\n<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u0447\u0438\u043d\u0430:<\/strong> \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432, \u0430 \u043f\u0430\u043a\u0435\u0442 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438 (<code>python-dev<\/code>) \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d.<\/p>\n<p><strong>\u0420\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<pre><code class=\"language-bash\">apt install python3.12-dev\n<\/code><\/pre>\n<p><strong>\u0433\u0434\u0435 <code>3.12<\/code> \u2014 \u0432\u0435\u0440\u0441\u0438\u044f Python, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0443\u0436\u0435\u043d <code>dev<\/code>-\u043f\u0430\u043a\u0435\u0442.<\/strong><\/p>\n<hr \/>\n<h2>\u0422\u043e\u043d\u043a\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438<\/h2>\n<ul>\n<li><strong>PEP 668 (externally-managed-environment)<\/strong> \u2014 \u0432 Ubuntu 23.04+ \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 <code>pip install<\/code> \u0431\u0435\u0437 <code>--break-system-packages<\/code> \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>venv<\/code> \u0438\u043b\u0438 <code>pipx<\/code>.<\/li>\n<li><strong><code>deadsnakes<\/code><\/strong> \u2014 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 PPA; \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0439\u0442\u0435 \u0440\u0438\u0441\u043a\u0438 \u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0439\u0442\u0435 \u0432\u0435\u0440\u0441\u0438\u0438.<\/li>\n<li><strong><code>update-alternatives<\/code><\/strong> \u2014 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e CLI; \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0437\u0430\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u0443\u0442\u044c Python, \u043d\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044e\u0442\u0441\u044f.<\/li>\n<li><strong><code>python3-venv<\/code><\/strong> \u2014 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0434\u043b\u044f <code>python -m venv<\/code>; \u0431\u0435\u0437 \u043d\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044c <code>venv<\/code> \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d.<\/li>\n<li><strong><code>WorkingDirectory<\/code> \u0432 systemd<\/strong> \u2014 \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435, \u0438\u043d\u0430\u0447\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0443\u0442\u0438 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043d\u0435 \u043d\u0430\u0439\u0434\u0443\u0442 \u0444\u0430\u0439\u043b\u044b.<\/li>\n<li><strong><code>Restart=on-failure<\/code><\/strong> \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u0443\u043f\u0430\u0432\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/li>\n<li><strong><code>KillMode=process<\/code><\/strong> \u2014 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0430\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/li>\n<li><strong>\u0412\u0435\u0440\u0441\u0438\u0438 Python<\/strong> \u2014 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0439\u0442\u0435 \u043c\u0438\u043d\u043e\u0440\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u0445; 3.13\/3.14 \u0443\u0436\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430<\/h2>\n<pre><code class=\"language-bash\"># \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\napt install python3.12 python3-pip\nadd-apt-repository ppa:deadsnakes\/ppa &amp;&amp; apt install python3.13\n\n# \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e\nupdate-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.12 0\nupdate-alternatives --config python\n\n# venv\napt install python3.12-venv\npython3.12 -m venv venv &amp;&amp; source venv\/bin\/activate\npip install -r requirements.txt\n\n# systemd\nsystemctl enable --now my-app\n<\/code><\/pre>\n<p><em>\u041f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043e \u043d\u0430: Ubuntu 22.04\/24.04\/26.04 + Python 3.10\u20133.14.<\/em><br \/>\n<em>\u0414\u0430\u0442\u0430: \u0421\u0435\u043d\u0442\u044f\u0431\u0440\u044c 2026.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Python \u043d\u0430 Ubuntu: \u0432\u0435\u0440\u0441\u0438\u0438, pip, venv, systemd<\/p>\n","protected":false},"author":0,"featured_media":974,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-945","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"aioseo_notices":[],"views":12,"_links":{"self":[{"href":"https:\/\/imaxis.ru\/index.php?rest_route=\/wp\/v2\/posts\/945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imaxis.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imaxis.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/imaxis.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=945"}],"version-history":[{"count":2,"href":"https:\/\/imaxis.ru\/index.php?rest_route=\/wp\/v2\/posts\/945\/revisions"}],"predecessor-version":[{"id":948,"href":"https:\/\/imaxis.ru\/index.php?rest_route=\/wp\/v2\/posts\/945\/revisions\/948"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imaxis.ru\/index.php?rest_route=\/wp\/v2\/media\/974"}],"wp:attachment":[{"href":"https:\/\/imaxis.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imaxis.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imaxis.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}