首页 > 其他分享 >Troubleshooting ‘Externally Managed Environment’ Error in Debian 12 Pip3 Installation

Troubleshooting ‘Externally Managed Environment’ Error in Debian 12 Pip3 Installation

时间:2023-11-30 14:32:09浏览次数:49  
标签:EXTERNALLY Externally 12 Managed package pipx Environment install error

https://medium.com/@kiena/troubleshooting-externally-managed-environment-error-in-debian-12-pip3-installation-439d62e5a970

 

When working with Python on Debian 12, you may encounter an error message regarding an ‘Externally Managed Environment’.

This error can hinder your use of pip3, the package installer for Python. Fortunately, there are several methods to troubleshoot and resolve this issue. In this guide, we will explore various approaches to fix the 'Externally Managed Environment' error and get pip3 back on track.

Error Encounter

Fix PIP using Apt

One straightforward way to address the ‘Externally Managed Environment’ error is by using the apt package manager to reinstall or update pip3. This can be done with the following command:

# you can change flask with other packages
sudo apt install python3-flask

Fix PIP by Creating a Virtual Environment (Recomendded)

Creating a virtual environment is a recommended method for isolating your Python projects and avoiding conflicts. To fix the ‘Externally Managed Environment’ error, you can create a virtual environment using the following steps:

# Install the Python3 venv package if not already installed
sudo apt install python3-venv

# Create a new virtual environment
python3 -m venv myenv

# Activate the virtual environment
source myenv/bin/activate

Then, install the package you want to pip install flask.

Fix PIP with PIPX

Pipx is a tool that helps you manage Python packages and provides an alternative to using sudo for package installations. follow these steps:

# Install pipx if not already installed
sudo apt install pipx

install pipx

# Ensure the local path for pipx
pipx ensurepath

ensurepath

# Use pipx to install flask or another package you need
pipx install flask

Install flask

# List all installed package
pipx list

# Run the package, here flask as example
pipx run flask run

Run flask

Fix Pip by Removing EXTERNALLY-MANAGED

If the error persists, you can try removing the EXTERNALLY-MANAGED file, which might be causing the issue. However, before you proceed, make sure to back up the file to a safe location. You can use the following command to back up the file to your ~/Project directory:

# If you want change the folder, change the /Project
sudo cp /usr/lib/python3.11/EXTERNALLY-MANAGED ~/Project/EXTERNALLY-MANAGED-BACKUP

# Remove EXTERNALLY-MANAGED file in your python library
sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED

Remove EXTERNALLY-MANAGED

Remember, removing system files should be approached with caution, and it’s always a good practice to back up before making any changes.

Conclusion

In this guide, we explored different methods to troubleshoot and fix the ‘Externally Managed Environment’ error in Debian 12 when working with pip3. By reinstalling or updating pip3 using apt, creating virtual environments, utilizing pipx, and cautiously removing the EXTERNALLY-MANAGED file, you can effectively resolve the error and continue seamless package management. These solutions empower you to navigate the challenges and ensure a smooth Python development experience on your Debian 12 system.



标签:EXTERNALLY,Externally,12,Managed,package,pipx,Environment,install,error
From: https://blog.51cto.com/u_847102/8629981

相关文章

  • P1084 [NOIP2012 提高组] 疫情控制
    首先军队可以原地不动,时间越多越容易合法,先套上二分。在不回到根的情况下,军队深度肯定越小越好。所以军队能往上移就移,如果能回到根就暂时在根对应的儿子那里驻扎。这个过程用树上倍增优化。做完这一步后,我们找出需要军队驻扎的根的儿子(向下不经过军队就能到达叶子),现在就是要让......
  • yzy第12次学习笔记
    第14章MySQL数据库系统MySQL(MySQL2018)是一个关系数据库系统。在关系数据库中,数据存储在表中。每个表由多个行和列组成。表中的数据相互关联,表也可能与其他表有关联。MySQL是一个开源数据库管理系统,由服务器和客户机组成。在将客户机连接到服务器后,用户可向服务器输入SQL命令......
  • 学习笔记12
    第十四章MySQL数据库系统PHPMySQL编程数据库连接:使用PHP连接MySQL数据库,主要方法是使用MySQLi扩展或PDO扩展。通过建立数据库连接,可以实现与数据库的通信。数据库操作:掌握创建、删除、修改和查询数据库表的操作。这包括表结构的定义(如字段类型、主键、外键等)、数据的插入......
  • P1081 [NOIP2012 提高组] 开车旅行
    题目有点长,一步一步来。预处理出每座城市两人分别会选择的下一座城市用set即可实现。倍增优化DP令\(f_{i,j}\)表示从城市\(j\)出发,行驶\(2^i\)天会到达的城市。令\(ga_{i,j}\)表示从城市\(j\)出发,行驶\(2^i\)天,小A行驶的路程。\(gb_{i,j}\)同理。答案枚......
  • 12.kafka单集群安装部署
    一.安装jdk,kafka需要至少jdk8+1.安装jdkyuminstalljava-11-openjdk.x86_64-y 2.查看安装是否正常[root@localhostbin]#java--versionopenjdk11.0.212023-10-17LTSOpenJDKRuntimeEnvironment(Red_Hat-11.0.21.0.9-1.el7_9)(build11.0.21+9-LTS)OpenJDK......
  • 学习笔记12
    MySQL数据库系统笔记1.概述MySQL是一种关系型数据库管理系统,广泛用于Web应用程序的后台数据存储。它是一个开源的数据库系统,提供高性能、稳定可靠的数据存储和管理功能。2.安装和配置2.1安装MySQL安装MySQL的步骤如下:下载适合操作系统的MySQL安装包。运行安装程序并按......
  • [20231124]奇怪的高逻辑读4.txt
    [20231124]奇怪的高逻辑读4.txt--//很长一段在生产系统看到一条逻辑读很高的sql语句,检查发现谓词使用了DBMS_LOB.SUBSTR函数.--//开发真奇葩,我无论如何也想不出开发为什么这些写代码,当时脑子短路了,使用trunc还好理解一点.--//我开始以为主要原因是lob类型导致fetch记录是1行1......
  • 20231129
    周六应该有一位新(老)同学要来机房。gm今晚还问我我旁边的电脑是不是好的。(我空着一个电脑坐只是为了远离某个【数据删除】的人。)突然觉得和自己的经历就很像。但是这也不能说是非常相似吧。说实话挺担心这位同学是否能跟得上进度的,以及,更关键的是机房的氛围(懂的都懂(放学......
  • 初中英语优秀范文100篇-012 My Experience of Being a Volunteer - 我的一次志愿者经
    PDF格式公众号回复关键字:SHCZFW012记忆树1Lastyear,Ipaidavisittothehomefortheagedwithmyclassmatesasvolunteers.翻译去年,我和我的同学作为志愿者去老年人之家探望了老人们。简化记忆探望老人句子结构这个句子可以分为四个主要部分:1状语短语:“La......
  • 1125笔记
    1、状态监控#创建虚拟主机文件,查看status功能​[root@web-8/etc/nginx/conf.d]#catstatus.conf#作用就是让你访问ip:9999可以精确定位到这个虚拟主机server{ listen9999; server_name_;stub_statuson;access_logoff;#因为它不是一个基于http请求响应......