How can I use pipx version of a package by default?

158 Views Asked by At

I'm on ubuntu 20.04 and trying to get my PC to use the pipx version of ansible by default, because the version installed by my package manager is too old.

I tried to use the instructions here (amongst a lot of others) to get the new version of ansible to run when I type simply, "ansible", but it won't use that version.

user@pcname:~$ /home/user/.local/pipx/venvs/ansible/bin/ansible --version

ansible [core 2.13.13]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr
/share/ansible/plugins/modules']
  ansible python module location = /home/user/.local/pipx/venvs/ansible/lib/pyt
hon3.8/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansi
ble/collections
  executable location = /home/user/.local/pipx/venvs/ansible/bin/ansible
  python version = 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0]
  jinja version = 3.1.3
  libyaml = True

user@pcname:~$ ansible --version
bash: /home/user/.local/bin/ansible: No such file or directory

127 user@pcname:~$ ll /home/user/.local/pipx/venvs/ansible/bin/
total 276
drwxrwxr-x 2 user user 4096 Feb  8 10:11 ./
drwxrwxr-x 6 user user 4096 Feb  2 18:22 ../
-rw-r--r-- 1 user user 2202 Feb  8 10:11 activate
-rw-r--r-- 1 user user 1254 Feb  8 10:11 activate.csh
-rw-r--r-- 1 user user 2406 Feb  8 10:11 activate.fish
-rw-r--r-- 1 user user 8834 Feb  8 10:11 Activate.ps1
-rwxrwxr-x 1 user user  248 Feb  2 18:22 ansible*
-rwxrwxr-x 1 user user  268 Feb  2 18:23 ansible-community*
-rwxrwxr-x 1 user user  249 Feb  2 18:22 ansible-config*
-rwxrwxr-x 1 user user  278 Feb  2 18:22 ansible-connection*
-rwxrwxr-x 1 user user  250 Feb  2 18:22 ansible-console*
-rwxrwxr-x 1 user user  246 Feb  2 18:22 ansible-doc*
-rwxrwxr-x 1 user user  249 Feb  2 18:22 ansible-galaxy*
-rwxrwxr-x 1 user user  252 Feb  2 18:22 ansible-inventory*
-rwxrwxr-x 1 user user  251 Feb  2 18:22 ansible-playbook*
-rwxrwxr-x 1 user user  247 Feb  2 18:22 ansible-pull*
-rwxrwxr-x 1 user user 1732 Feb  2 18:22 ansible-test*
-rwxrwxr-x 1 user user  248 Feb  2 18:22 ansible-vault*
-rwxrwxr-x 1 user user  263 Feb  2 18:22 easy_install*
-rwxrwxr-x 1 user user  263 Feb  2 18:22 easy_install-3.8*
-rwxrwxr-x 1 user user  253 Feb  8 10:11 pip*
-rwxrwxr-x 1 user user  253 Feb  8 10:11 pip3*
-rwxrwxr-x 1 user user  253 Feb  8 10:11 pip3.8*
lrwxrwxrwx 1 user user    7 Feb  2 18:10 python -> python3*
lrwxrwxrwx 1 user user   16 Feb  2 18:10 python3 -> /usr/bin/python3*

user@pcname:~$ apt-cache policy ansible
ansible:
  Installed: (none)
  Candidate: 5.10.0-1ppa~focal
  Version table:
     5.10.0-1ppa~focal 500
        500 http://ppa.launchpad.net/ansible/ansible/ubuntu focal/main amd64 Pac
kages
        500 http://ppa.launchpad.net/ansible/ansible/ubuntu focal/main i386 Pack
ages
     2.9.6+dfsg-1 500
        500 http://au.archive.ubuntu.com/ubuntu focal/universe amd64 Packages
        500 http://au.archive.ubuntu.com/ubuntu focal/universe i386 Packages

user@pcname:~$ ansible
bash: /home/user/.local/bin/ansible: No such file or directory

127 user@pcname:~$ ansible --version
bash: /home/user/.local/bin/ansible: No such file or directory

127 user@pcname:~$ which ansible
/usr/bin/ansible

user@pcname:~$ whereis ansible
ansible: /usr/bin/ansible /etc/ansible /usr/share/ansible /usr/share/man/man1/an
sible.1.gz

user@pcname:~$ pip install --user pipx
Requirement already satisfied: pipx in /usr/lib/python3/dist-packages (0.12.3.1)
DEPRECATION: mythtv 31.0.-1 has a non-standard version number. pip 24.0 will enf
orce this behaviour change. A possible replacement is to upgrade to a newer vers
ion of mythtv or contact the author to suggest that they release a version with
a conforming version number. Discussion can be found at https://github.com/pypa/
pip/issues/12063

user@pcname:~$ pipx ensurepath
Your PATH looks like it already is set up for pipx. Pass `--force` to modify the
 PATH.

user@pcname:~$ pipx list
venvs are in /home/user/.local/pipx/venvs
binaries are exposed on your $PATH at /home/user/.local/bin
   package ansible 6.7.0, Python 3.8.10
    - ansible-community
   package ansible-core 2.13.13, Python 3.8.10
    - __init__.py
    - ansible_connection_cli_stub.py
    - ansible (symlink not installed)
    - ansible-config (symlink not installed)
    - ansible-connection (symlink not installed)
    - ansible-console (symlink not installed)
    - ansible-doc (symlink not installed)
    - ansible-galaxy (symlink not installed)
    - ansible-inventory (symlink not installed)
    - ansible-playbook (symlink not installed)
    - ansible-pull (symlink not installed)
    - ansible-test (symlink not installed)
    - ansible-vault (symlink not installed)

user@pcname:~$ ll /home/user/.local/bin/ansible*
lrwxrwxrwx 1 user user 59 Feb  2 18:23 /home/user/.local/bin/ansible-communit
y -> /home/user/.local/pipx/venvs/ansible/bin/ansible-community*
lrwxrwxrwx 1 user user 77 Feb  2 18:12 /home/user/.local/bin/ansible_connecti
on_cli_stub.py -> /home/user/.local/pipx/venvs/ansible-core/bin/ansible_connect
ion_cli_stub.py

I suppose it's not working because of those "symlink not installed" messages but I don't know how to fix it.

Edit:

user@pcname:~$ ll /usr/bin/ansible
-rwxr-xr-x 1 root root 5915 Oct 26  2022 /usr/bin/ansible*

user@pcname:~$ /usr/bin/ansible --version
ansible [core 2.12.10]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0]
  jinja version = 3.1.3
  libyaml = True
0

There are 0 best solutions below