ansible / ansible-builder

An Ansible execution environment builder
Other
292 stars 97 forks source link

Python interpreter cannot find site packages #589

Closed shatakshiiii closed 1 year ago

shatakshiiii commented 1 year ago

SUMMARY

Building an execution-environment with builder v3 cannot find a path to python interpreter. And hence not able to find the python packages that are installed inside that path.

STEPS TO REPRODUCE

  1. Create a EE image localhost/ee:0.0.1 with file execution-environment.yml with given content.
---
version: 3

images:
  base_image:
    name: quay.io/fedora/python-311:latest

dependencies:
  ansible_core:
    package_pip: ansible-core
  ansible_runner:
    package_pip: ansible-runner
  galaxy:
    collections:
      - community.general
  python:
    - ansible-lint
  1. Build the EE with ansible-builder 3.0.0:
    ansible-builder build -t ee:0.0.1
    1. Run: podman run -it ee:0.0.1 and after that do: python -m site

Expected behaviour

I should see a path to: /usr/local/lib/python3.11/site-packages in the list of sys.path

Actual Behaviour

There is no path mentioned as: /usr/local/lib/python3.11/site-packages inside that EE.

(app-root) python -m site
sys.path = [
    '/home/user/Ansible/ansible-navigator',
    '/usr/lib64/python311.zip',
    '/usr/lib64/python3.11',
    '/usr/lib64/python3.11/lib-dynload',
    '/opt/app-root/lib64/python3.11/site-packages',
    '/opt/app-root/lib/python3.11/site-packages',
]
USER_BASE: '/root/.local' (doesn't exist)
USER_SITE: '/root/.local/lib/python3.11/site-packages' (doesn't exist)
ENABLE_USER_SITE: False

Moreover: pip freeze inside that EE gives no output as it can't find any installed python package.

(app-root) pip freeze
(app-root) 
Shrews commented 1 year ago

Give the full path to the python3 binary (builder defaults to /usr/bin/python3 unless you manually specify a different path), which will influence the paths it uses:

(app-root) /usr/bin/python3 -m site
sys.path = [
    '/runner',
    '/usr/lib64/python311.zip',
    '/usr/lib64/python3.11',
    '/usr/lib64/python3.11/lib-dynload',
    '/usr/local/lib64/python3.11/site-packages',
    '/usr/local/lib/python3.11/site-packages',
    '/usr/lib64/python3.11/site-packages',
    '/usr/lib/python3.11/site-packages',
]
USER_BASE: '/runner/.local' (doesn't exist)
USER_SITE: '/runner/.local/lib/python3.11/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
(app-root) /usr/bin/python3 -m pip freeze
ansible-compat==4.1.5
ansible-core==2.15.2
ansible-lint==6.17.2
ansible-runner==2.3.3
...
Shrews commented 1 year ago

Not a builder problem, so closing this issue.