Python/Etc
[Python] pip install error: externally-managed-environment 해결 방법
써니의 연습장
2025. 6. 26. 04:37
1. Python 환경
- Ubuntu 24.04
- Python 3.12
2. Error 발생 상황
- pip를 이용해 패키지를 설치할 때, 아래와 같이 에러가 발생
# pip install streamlit
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.12/README.venv for more information.
note: 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.
hint: See PEP 668 for the detailed specification.
3. 해결 방법
- 위 설명대로 pip를 이용해 패키지를 설치할 경우, 시스템에 영향을 줄 수 있다고 하면서 발생한 에러
- 개발자가 외부 패키지를 설치해도 문제가 없다고 판단 된다면한다면, 위의 설명과 같이 pip에 권한을 부여해서 패키지를 설치할 수 있도록 아래와 같은 커맨드 명령으로 설정 변경
python3 -m pip config set global.break-system-packages true
- 위 커맨드를 실행하면 아래와 같이 /root/.config.pip/pip.conf 파일을 수정했다고 출력 됨
# python3 -m pip config set global.break-system-packages true
Writing to /root/.config/pip/pip.conf
- 위와 같이 설정한 이후에 다시 pip를 통해 패키지를 설치하면, 패키지가 정상적으로 잘 설치되는 것을 확인 가능