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

prefering python2 causes failure because of missing dependancies #189

Open
archf opened this issue Jan 9, 2019 · 5 comments
Open

prefering python2 causes failure because of missing dependancies #189

archf opened this issue Jan 9, 2019 · 5 comments

Comments

@archf
Copy link

archf commented Jan 9, 2019

This logic in /usr/local/bin/ansible-cmdb makes it that python2 is picked even when python3 is available and as dependencies got installed under python3 it will fail:

# Find python binary
PY_BIN=$(which python)
if [ -z "$PY_BIN" ]; then
    PY_BIN=$(which python3)
fi
if [ -z "$PY_BIN" ]; then
    echo "No python found. Aborting"
    exit 1
fi

e.g:

archf@wm ~/r/w/g/m/o/scripts master?> /usr/local/bin/ansible-cmdb -h
Traceback (most recent call last):
  File "/usr/local/bin/../lib/ansiblecmdb/ansible-cmdb.py", line 19, in <module>
    from mako import exceptions
ImportError: No module named mako

I think it should try python3 first. My operating system is Ubuntu 18.04. I suspect it might be working only on Fedora,RHEL,CentOS as of now.

Regards, Thanks for coding this software.

@fboender
Copy link
Owner

fboender commented Mar 6, 2019

Hi Felix!

Sorry for the late reply! I've been very busy.

There's a very good chance that this will be fixed by the pull request in #190. I'll try that one out soon, and if it fixes this problem, I'll update this ticket.

@archf
Copy link
Author

archf commented Mar 7, 2019 via email

@hoexter
Copy link

hoexter commented Sep 23, 2019

@fboender we're running into this issue on systems with "python" and "python3" where the former is python2. I think the current implementation in https://github.com/fboender/ansible-cmdb/blob/master/src/ansible-cmdb will not fix the issue at hand.
https://github.com/fboender/ansible-cmdb/blob/master/src/ansible-cmdb#L14 will still only see one python interpreter, which on most systems is just python2.

My personal preference would be to check for an environment variable to refer to the python interpreter to use. If it's set use the one defined, otherwise run the detection logic.

Even if you would run "which -a python python3" (to cover the most common interpreter) you would still default to the first one, which might or my not be a good choice for the current user.

@iacgg
Copy link

iacgg commented Jun 8, 2021

I got the same bug in my CI/CD i fixed by adding a symlink from python3 to python
ln -s /usr/bin/python3 /usr/bin/python
I guess something is looking for python and not python3.

@iacgg
Copy link

iacgg commented Jun 8, 2021

I guess this line could be improved a bit

which -a python | while read -r TRY_PY_BIN

its a little old school to only look for "python" but i have not looked much into it, hope it can help.
Simple one that could be tested which -a python python3

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

No branches or pull requests

4 participants