Skip to content

Error Installing Python Docker Module in Managed Environment #17

@MAVRICK-1

Description

@MAVRICK-1

Title: Error Installing Python Docker Module in Managed Environment

Description:
The installation process fails during the install docker module for Python task due to the error externally-managed-environment. This occurs because the Python environment is marked as externally managed, and direct installations using pip are restricted without using a virtual environment or passing the --break-system-packages flag.

Error Output:

Image

Steps to Reproduce:

  1. Run the make aether-gnbsim-install command as shown in the logs.
  2. Observe the failure during the install docker module for Python task.

Expected Behavior:
The playbook should successfully install the Python docker module without errors.

Actual Behavior:
The task fails with a fatal error, indicating that the Python environment is externally managed.

Solution:
The issue was resolved by creating a Python virtual environment and installing the docker module within it. Here is the updated install.yml playbook snippet:

- name: Create a virtual environment for Python
  ansible.builtin.command:
    cmd: python3 -m venv /opt/dockerenv
  when: inventory_hostname in groups['gnbsim_nodes']
  become: true

- name: Install docker module for Python in virtual environment
  pip:
    name: docker
    virtualenv: /opt/dockerenv
  when: inventory_hostname in groups['gnbsim_nodes']
  become: true

Key Notes:

  • Using a virtual environment isolates the Python dependencies and avoids conflicts with the system-wide package manager.
  • This approach complies with the externally-managed-environment restriction in modern Python distributions.
  • No need to override the restriction (--break-system-packages) or use pipx as additional tools.

Environment:

  • OS: Ubuntu (specific version can be added)
  • Python Version: Python 3.12
  • Ansible Version: Provide the version used
  • Playbook File: install.yml

Additional Updates:
The remaining tasks (such as pulling the Docker image and setting up user permissions) worked as expected without further modifications.

@llpeterson I have already solve this issue rasing a PR for this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions