Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work properly when Python is installed from source #35

Closed
davidfischer-ch opened this issue Nov 6, 2019 · 8 comments
Closed

Comments

@davidfischer-ch
Copy link

davidfischer-ch commented Nov 6, 2019

This issue is related to #19.

Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 92, in <module>
    mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
  File "/usr/local/lib/python3.7/site-packages/ansible/cli/__init__.py", line 25, in <module>
    from ansible.parsing.dataloader import DataLoader
  File "/usr/local/lib/python3.7/site-packages/ansible/parsing/dataloader.py", line 17, in <module>
    from ansible.module_utils.basic import is_executable
  File "/usr/local/lib/python3.7/site-packages/ansible/module_utils/basic.py", line 74, in <module>
    import selinux
  File "/usr/local/lib/python3.7/site-packages/selinux/__init__.py", line 104, in <module>
    check_system_sitepackages()
  File "/usr/local/lib/python3.7/site-packages/selinux/__init__.py", line 93, in check_system_sitepackages
    system_sitepackages = get_system_sitepackages()
  File "/usr/local/lib/python3.7/site-packages/selinux/__init__.py", line 83, in get_system_sitepackages
    "import json, site; print(json.dumps(site.getsitepackages()))",
  File "/usr/local/lib/python3.7/subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "/usr/local/lib/python3.7/subprocess.py", line 488, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/local/lib/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/usr/local/lib/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/python3': '/usr/bin/python3'
$ which python3
/usr/local/bin/python3
$ python3
Python 3.7.5 (default, Nov  5 2019, 12:24:42)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/usr/local/bin/python3'
@ssbarnea
Copy link
Member

ssbarnea commented Nov 6, 2019

My impression that this far outside a supported use-case but if you have some ideas on how to cover it, feel free to propose it.

@ssbarnea
Copy link
Member

ssbarnea commented Jan 9, 2020

I will close this because I do not see anything actionable about it. Still if anyone else has a different idea, I am willing to reopen it.

@ssbarnea ssbarnea closed this as completed Jan 9, 2020
@ghost
Copy link

ghost commented Jan 28, 2021

Hey @ssbarnea, it would be better if we could check if python is installed to an alternate root by using something like sys.base_prefix for instance which would map to that path and prevent from breaking for systems where python is installed under /opt or /usr/local as mentioned above. I could work on a PR for this if you'd like

@ssbarnea
Copy link
Member

I was about to say, that I will always look at PRs. Make one that does not break on redhat family and I will likely approve it. I also happen to use pyenv a lot, so I should be able to provide extra feedback on it. The tricky bit here is that someone still needs to compile the real selinux for that particular python version or this extension will not work.

Keep in mind that this extension is shim that allows a venv to access selinux from python. If is missing, it will not help.

@ghost
Copy link

ghost commented Feb 6, 2021

Hey @ssbarnea, looks like libselinux-python3 in it's current offering is heavily tied to the system python that redhat ships with for both 7 and 8 and also to a specific python version (3.6). As a good workaround, I could just have the system python with selinux bindings(libselinux-python) and install this extension on the built distribution (under /opt). It seems to be treating it similar to a venv and some of the ansible modules which depend on it, seem to satisfy my use cases without complicating things. Thanks for the quick response and maintaining this project.

@mcamposv
Copy link

mcamposv commented Mar 9, 2021

Hello,
Today I came around this issue too.
my ansible was "broken" because after installing molecule now it has a dependency on selinux.
unfortunately, my python is installed under /opt/xxx compiled from sourcecode. in order to get latest versions and be independent from the OS version.
I do not fully understand @constreference last solution.
let alone the root of the issue.
I just wanted to say that there is another user hitting this. trying to figure out the best solution/workarround.
Thanks.

@ssbarnea
Copy link
Member

ssbarnea commented Mar 9, 2021

Ansible has a dependency on selinux for many core modules, make ansible work under your python interpreter and I am confident that molecule will work too.

@williamhanseneric
Copy link

I just hit this issue in a real world use case. I have an Ansible Tower environment where both python2 and python3 are in use, and the default enabled is python2. I cannot enable the system python3 for general use, but when users build venvs they can point to the python3 installation location in /opt/rh/... for python3. But, we hit this problem now on upgrading the venv to a more recent version of our packages and weren't hitting any selinux requirement before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants