{"id":45931,"date":"2024-03-25T12:23:01","date_gmt":"2024-03-25T12:23:01","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=45931"},"modified":"2025-05-23T12:28:42","modified_gmt":"2025-05-23T12:28:42","slug":"pip-install-error-ubuntu-2404","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/03\/pip-install-error-ubuntu-2404\/","title":{"rendered":"How to Fix Python Pip Install Error in Ubuntu 24.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>When using <code>pip<\/code> command to install a Python package in Ubuntu 24.04 will output &#8220;<b>error: externally-managed-environment<\/b>&#8220;. Here are a few workarounds to &#8216;fix&#8217; the issue.<\/p>\n<p>As the terminal output shows you, it&#8217;s the change due to <a href=\"https:\/\/peps.python.org\/pep-0668\/\" target=\"_blank\" rel=\"noopener\">PEP 668<\/a>. Since Ubuntu 23.04, it recommends Python-specific package management tools (e.g., pip) to install packages using a virtual environment, to avoid conflicts to packages installed by OS package managers. Though, user can still force pip to install into interpreter\u2019s global context just like before.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-install-error.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45932\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-install-error-700x489.webp\" alt=\"\" width=\"610\" height=\"426\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-install-error-700x489.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-install-error-300x210.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-install-error-768x537.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-install-error.webp 866w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><br \/>\n<!--more--><\/p>\n<p><b>The workarounds to this issue so far include:<\/b><\/p>\n<ul>\n<li>Install the Python package from system repository if exist.<\/li>\n<li>Force pip to install just like before in 22.04.<\/li>\n<li>Use pipx instead (Python apps only).<\/li>\n<li>Manually create virtual environment and install package into it.<\/li>\n<\/ul>\n<h3>Option 1: Install Python package from System Repository<\/h3>\n<p>Debian and Ubuntu include a few thousands of Python packages in system repositories. Before installing a package via <code>pip<\/code>, it&#8217;s better to first take a look if a corresponding OS package is available.<\/p>\n<p>To do so, either use Synaptic package manager (available in App Center) or run sudo apt install python3- command and press &#8220;Tab&#8221; to list available choices.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-packages-repos.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45933\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-packages-repos-700x442.webp\" alt=\"\" width=\"610\" height=\"385\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-packages-repos-700x442.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-packages-repos-300x189.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-packages-repos-768x485.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-packages-repos.webp 1308w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Also the <a href=\"https:\/\/packages.ubuntu.com\/\" target=\"_blank\" rel=\"noopener\">packages.ubuntu.com<\/a> web page provides search function to find packages from system repository.<\/p>\n<h3>Option 2: Force pip to install just like before<\/h3>\n<p>As the terminal error output shows, user can bypass by adding <code>--break-system-packages<\/code> flag.<\/p>\n<p>For example, force install <code>imagesearch<\/code> library via command:<\/p>\n<pre>pip install --user imagesearch --break-system-packages<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-systempackages.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45934\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-systempackages-700x489.webp\" alt=\"\" width=\"610\" height=\"426\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-systempackages-700x489.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-systempackages-300x210.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-systempackages-768x537.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-systempackages.webp 866w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Without typing <code>--break-system-packages<\/code> every time running the pip install command, you may write the rule into configuration file. To do so, simply run commands:<\/p>\n<pre>mkdir -p ~\/.config\/pip<\/pre>\n<pre>echo -e \"[global]\\nbreak-system-packages=true\" &gt; ~\/.config\/pip\/pip.conf<\/pre>\n<p>The commands will first create <code>~\/.config\/pip<\/code> folder if not exist, then create <code>pip.conf<\/code> config file and write following lines into it:<\/p>\n<pre>[global]\r\nbreak-system-packages=true<\/pre>\n<p>After that, you can use <code>pip install<\/code> command to install Python packages just like in Ubuntu 22.04 and earlier<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-install-conf.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45935\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-install-conf-700x438.webp\" alt=\"\" width=\"610\" height=\"382\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-install-conf-700x438.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-install-conf-300x188.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-install-conf-768x481.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pip-break-install-conf.webp 866w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Option 3: Use pipx<\/h3>\n<p>Pipx is an alternative command line tool to install and run Python applications in isolated environments. It&#8217;s however for <b>Pythons apps only<\/b>.<\/p>\n<p>To install and setup pipx, simply run command:<\/p>\n<pre>sudo apt install pipx<\/pre>\n<pre>pipx ensurepath<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/apt-pipx.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45936\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/apt-pipx-700x438.webp\" alt=\"\" width=\"610\" height=\"382\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/apt-pipx-700x438.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/apt-pipx-300x188.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/apt-pipx-768x481.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/apt-pipx.webp 866w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Then you can install a Python app via pipx, for example cowsay, use command:<\/p>\n<pre>pipx install cowsay<\/pre>\n<p>Then run it via:<\/p>\n<pre>pipx run cowsay --text \"Mooo\"<\/pre>\n<p>And use command to uninstall Python package:<\/p>\n<pre>pipx uninstall cowsay<\/pre>\n<p>For more about pipx, either run <code>pipx --help<\/code> or go to its <a href=\"https:\/\/github.com\/pypa\/pipx\" target=\"_blank\" rel=\"noopener\">project page<\/a>.<br \/>\n<a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pipx-usage.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45937\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pipx-usage-700x489.webp\" alt=\"\" width=\"610\" height=\"426\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pipx-usage-700x489.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pipx-usage-300x210.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pipx-usage-768x537.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/pipx-usage.webp 866w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Option 4: Manually Create Virtual Environment for Installing Python package<\/h3>\n<p>1. If you want to manually create virtual environment for installing a Python package in Ubuntu 24.04, then open terminal and run command:<\/p>\n<pre>python3 -m venv ~\/.venv\/cowsay<\/pre>\n<p><i>This command will create <code>.venv\/cowsay<\/code> directory in your user home (replace <code>cowsay<\/code> to your own name). By running <code>ls ~\/.venv\/cowsay<\/code>, you can see that the folder contains a copy of Python executables and libraries.<\/i><\/p>\n<p>2. After running the command above to create the virtual Python environment, you may then run the <code>pip<\/code> command from that directory to install a Python package. For example:<\/p>\n<pre>~\/.venv\/cowsay\/bin\/pip install cowsay<\/pre>\n<p>Finally, run the installed Python app from that virtual environment by running command:<\/p>\n<pre>~\/.venv\/cowsay\/bin\/cowsay -t \"Mooooo\"<\/pre>\n<p>You can install more Python packages into this single environment (<code>.venv\/cowsay<\/code> in my case), or run <code>python3 -m venv ~\/.venv\/NAME_HERE<\/code> again to create more virtual environments to use for other packages.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-manual-env.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45938\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-manual-env-700x523.webp\" alt=\"\" width=\"610\" height=\"456\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-manual-env-700x523.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-manual-env-300x224.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-manual-env-768x574.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/python-manual-env.webp 866w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h4>Add the Virtual Environment to your PATH<\/h4>\n<p>Without running the full path to <code>pip<\/code> and <code>python<\/code> executable files, you may add the virtual python environment to your PATH.<\/p>\n<p>To do so, either run command which works only in current terminal window:<\/p>\n<pre>export PATH=$HOME\/.venv\/cowsay\/bin:$PATH<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45939\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-700x562.webp\" alt=\"\" width=\"610\" height=\"490\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-700x562.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-300x241.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-768x616.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path.webp 806w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Or add the command above into user&#8217;s <b>.profile<\/b> file by running the command below. So, it will work anywhere in next login! To do so, first run command to edit user profile file:<\/p>\n<pre>nano ~\/.profile<\/pre>\n<p>When file opens, scroll down add new line <code>export PATH=$HOME\/.venv\/cowsay\/bin:$PATH<\/code> (replace <code>cowsay<\/code> to yours), finally press Ctrl+S to save, Ctrl+X to exit.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-profile.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45950\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-profile-700x471.webp\" alt=\"\" width=\"610\" height=\"410\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-profile-700x471.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-profile-300x202.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-profile-768x516.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/03\/venv-path-profile.webp 806w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Summary:<\/h3>\n<p>In this tutorial, I taught how to workaround the <code>pip install<\/code> command error in Ubuntu 24.04.<\/p>\n<p>For lazy men who want to make it work like before, just add <code>--break-system-packages<\/code> command option, though it might break things. While, the recommended way is to either install a replacement through OS package (if any), or create virtual environment and install the Python package into it.<\/p>","protected":false},"excerpt":{"rendered":"<p>When using pip command to install a Python package in Ubuntu 24.04 will output &#8220;error: externally-managed-environment&#8220;. Here are a few workarounds to &#8216;fix&#8217; the issue. As the terminal output shows you, it&#8217;s the change due to PEP 668. Since Ubuntu 23.04, it recommends Python-specific package management tools (e.g., pip) to install packages using a virtual [&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-45931","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-python"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/45931","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=45931"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/45931\/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=45931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=45931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=45931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}