{"id":853,"date":"2024-03-06T21:10:47","date_gmt":"2024-03-07T00:10:47","guid":{"rendered":"https:\/\/freeshell.de\/~felipe\/blog\/?p=853"},"modified":"2024-06-09T15:43:41","modified_gmt":"2024-06-09T18:43:41","slug":"externally-managed-environment-in-python","status":"publish","type":"post","link":"https:\/\/freeshell.de\/~felipe\/blog\/03\/2024\/linux\/externally-managed-environment-in-python\/","title":{"rendered":"The &#8211; externally-managed-environment &#8211; in Python"},"content":{"rendered":"\n<p>To avoid this message which is to force you somehow to create a virtual environment in python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ pip install .\nerror: externally-managed-environment\n\n\u00d7 This environment is externally managed\n??&gt; To install Python packages system-wide, try 'pacman -S\n    python-xyz', where xyz is the package you are trying to\n    install.\n\n    If you wish to install a non-Arch-packaged Python package,\n    create a virtual environment using 'python -m venv path\/to\/venv'.\n    Then use path\/to\/venv\/bin\/python and path\/to\/venv\/bin\/pip.\n\n    If you wish to install a non-Arch packaged Python application,\n    it may be easiest to use 'pipx install xyz', which will manage a\n    virtual environment for you. Make sure you have python-pipx\n    installed via pacman.\n\nnote: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.\nhint: See PEP 668 for the detailed specification.<\/code><\/pre>\n\n\n\n<p>Just remove this in Linux:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm \/usr\/lib\/python3.11\/EXTERNALLY-MANAGED<\/code><\/pre>\n\n\n\n<p>If you are using Homebrew just go to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/home\/linuxbrew\/.linuxbrew\/Cellar\/python@3.12\/3.12.2_1\/lib\/python3.12<\/code><\/pre>\n\n\n\n<p>and remove the file EXTERNALLY-MANAGED as well.<\/p>\n\n\n\n<p>If on the other side, prefer to create a virtual environment, this is the way, install this package: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3-venv<\/code><\/pre>\n\n\n\n<p>In the environment you prefer to work with, use this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3 -m venv .venv<\/code><\/pre>\n\n\n\n<p>You can check all the installed packaged here: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>user@server# ls .venv\/\nbin  include  lib  lib64  pyvenv.cfg<\/code><\/pre>\n\n\n\n<p>Then you have to activate the environment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source .venv\/bin\/activate<\/code><\/pre>\n\n\n\n<p>Then it&#8217;s possible to use pip to install packages in that environment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install -r requirements.txt<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install openai<\/code><\/pre>\n\n\n\n<p>That&#8217;s it.<\/p>\n\n\n\n<p>To deactivate the environment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>deactivate<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To avoid this message which is to force you somehow to create a virtual environment in python: Just remove this in Linux: If you are using Homebrew just go to: and remove the file EXTERNALLY-MANAGED as well. If on the other side, prefer to create a virtual environment, this is the way, install this package: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71,74,70,76,83],"tags":[66,105,67,87,80],"class_list":["post-853","post","type-post","status-publish","format-standard","hentry","category-arch","category-debian","category-linux","category-mac","category-python","tag-arch","tag-environment","tag-linux","tag-package","tag-python"],"_links":{"self":[{"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/posts\/853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/comments?post=853"}],"version-history":[{"count":7,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/posts\/853\/revisions"}],"predecessor-version":[{"id":862,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/posts\/853\/revisions\/862"}],"wp:attachment":[{"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/media?parent=853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/categories?post=853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freeshell.de\/~felipe\/blog\/wp-json\/wp\/v2\/tags?post=853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}