iam-veeramalla / Docker-Zero-to-Hero

Repo to learn Docker with examples. Contributions are most welcome.
https://www.youtube.com/@AbhishekVeeramalla
3.93k stars 7.9k forks source link

Resolve Python Package Installation Issue Due to PEP 668 in Recent Ubuntu Versions #51

Open hassanhah opened 6 months ago

hassanhah commented 6 months ago

Description: I'm encountering an error while trying to install Python packages in the system-wide Python environment on a recent version of Ubuntu. This issue seems to be related to restrictions implemented as per PEP 668, which aims to prevent conflicts between the system package manager and pip. Steps to Reproduce:

Attempt to install a Python package using pip in the system-wide environment on a recent Ubuntu version.

sh

pip install <package-name>

Observe the error message indicating the restriction.

Expected Behavior:

Python packages should be installed successfully without conflicts. Actual Behavior:

The installation fails with an error message due to the PEP 668 restriction. Suggested Solution:

To resolve this issue, create a virtual environment and install the required packages within that environment. This isolates the application's dependencies from the system-wide Python environment, which is a recommended practice. Steps to Create a Virtual Environment:

Install the virtualenv package if not already installed:

sh

sudo apt-get install python3-virtualenv

Create a new virtual environment:

sh

virtualenv myenv

Activate the virtual environment:

sh

source myenv/bin/activate

Install the required packages within the virtual environment:

sh

pip install <package-name>

References:

[PEP 668 – Marking Python base environments as “externally managed”](https://peps.python.org/pep-0668/)

Environment:

Ubuntu Version: [Specify version]
Python Version: [Specify version]
Pip Version: [Specify version]

Please look into this issue and provide guidance or a fix for the same. external manage env

Pavans3 commented 5 months ago

Hello everyone if You were facing this same issue just simple change Ubuntu version and your problem is resolve

FROM ubuntu:20.04

WORKDIR /app

COPY requirements.txt /app COPY devops /app

RUN apt-get update && \ apt-get install -y python3 python3-pip && \ pip install -r requirements.txt && \ cd devops

ENTRYPOINT ["python3"] CMD ["manage.py", "runserver", "0.0.0.0:8000"]

Screenshot (121) Screenshot (122)