{"id":88,"date":"2025-02-05T17:14:33","date_gmt":"2025-02-05T09:14:33","guid":{"rendered":"https:\/\/www.handytoo.com\/?p=88"},"modified":"2025-02-05T17:14:33","modified_gmt":"2025-02-05T09:14:33","slug":"ubuntu24lts%e4%bd%bf%e7%94%a8pip-install%e6%97%b6%e6%8f%90%e7%a4%ba%ef%bc%9aerror-externally-managed-environment%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.handytoo.com\/?p=88","title":{"rendered":"Ubuntu24LTS\u4f7f\u7528pip install\u65f6\u63d0\u793a\uff1aerror: externally-managed-environment\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"\n<p>Ubuntu24.04LTS\u4e2d\u4f7f\u7528apt\u6309\u7167pip\uff0c\u7136\u540epip install\u65f6\u4f1a\u63d0\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>error: externally-managed-environment\n\n\u00d7 This environment is externally managed\n\u2570\u2500> To install Python packages system-wide, try apt install\n    python3-xyz, where xyz is the package you are trying to\n    install.\n    \n    If you wish to install a non-Debian-packaged Python package,\n    create a virtual environment using python3 -m venv path\/to\/venv.\n    Then use path\/to\/venv\/bin\/python and path\/to\/venv\/bin\/pip. Make\n    sure you have python3-full installed.\n    \n    If you wish to install a non-Debian 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 pipx installed.\n    \n    See \/usr\/share\/doc\/python3.12\/README.venv for more information.\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.\n\n<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u9519\u8bef\u4fe1\u606f\u8868\u660e\u4f60\u6b63\u5728\u5c1d\u8bd5\u5728\u4e00\u4e2a\u7531Ubuntu\u7cfb\u7edf\u6216\u67d0\u4e9b\u7cfb\u7edf\u7ea7\u670d\u52a1\u7ba1\u7406\u7684Python\u73af\u5883\u4e2d\u4f7f\u7528pip\u6765\u5b89\u88c5\u5305\uff0c\u800c\u8fd9\u4e2a\u73af\u5883\u662f\u201c\u5916\u90e8\u7ba1\u7406\u201d\u7684\uff0c\u610f\u5473\u7740\u5b83\u53ef\u80fd\u5df2\u7ecf\u88abUbuntu\u7684\u67d0\u4e9b\u90e8\u5206\u6216\u5176\u4ed6\u7cfb\u7edf\u7ea7\u670d\u52a1\u6240\u4f9d\u8d56\u3002\u76f4\u63a5\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\u4f7f\u7528pip\u5b89\u88c5\u6216\u66f4\u65b0\u5305\u53ef\u80fd\u4f1a\u7834\u574f\u8fd9\u4e9b\u7cfb\u7edf\u7ea7\u670d\u52a1\u6216\u5e94\u7528\u7684\u8fd0\u884c\u3002<\/p>\n\n\n\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n\n\n\n<p>\u901a\u8fc7venv\u5305\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u5168\u5c40\u7684\u865a\u62df\u73af\u5883\uff0c\u7136\u540e\u65b0\u5efa\u4e00\u4e2a<code>enterpy3<\/code>\u522b\u540d\u6765\u6fc0\u6d3b\u5b83\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5venv\u5305<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo apt install python3-venv<\/code><\/code><\/pre>\n\n\n\n<p>\u7b2c\u4e8c\u6b65\uff1a\u521b\u5efa\u865a\u62df\u73af\u5883<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\nmkdir .python_venv\ncd .python_venv\npython3 -m venv global<\/code><\/pre>\n\n\n\n<p>\u7b2c\u4e09\u6b65\uff1a\u8bbe\u7f6e\u5207\u6362\u865a\u62df\u73af\u5883\u7684\u81ea\u5b9a\u4e49\u547d\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u7f16\u8f91bashrc\nvim ~\/.bashrc\n\u8ffd\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff0cwq\u4fdd\u5b58\nalias <span style=\"background-color: rgba(0, 0, 0, 0.2); font-family: inherit; font-size: inherit; color: initial;\">enterpy3<\/span><span style=\"font-family: inherit; font-size: inherit; color: initial; background-color: initial;\">='. ~\/.python_venv\/global\/bin\/activate'<\/span>\n\u91cd\u65b0\u52a0\u8f7dbashrc\nsource ~\/.bashrc<\/code><\/pre>\n\n\n\n<p>\u4ee5\u540e\u518d\u4f7f\u7528python\u524d\u90fd\u5148\u6267\u884c\u4e0b <code>enterpy3<\/code> \u547d\u4ee4\uff0c\u5207\u6362\u5230\u865a\u62df\u73af\u5883\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528pip\u6b63\u5e38\u5b89\u88c5\u5305\u548c\u8fd0\u884cpython\u811a\u672c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu24.04LTS\u4e2d\u4f7f\u7528apt\u6309\u7167pip\uff0c\u7136\u540epip install\u65f6\u4f1a\u63d0\u793a\uff1a \u8fd9\u4e2a\u9519\u8bef\u4fe1\u606f\u8868\u660e\u4f60\u6b63 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[24],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-python","tag-python"],"_links":{"self":[{"href":"http:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88"}],"version-history":[{"count":2,"href":"http:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":90,"href":"http:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions\/90"}],"wp:attachment":[{"href":"http:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}